Comments and answers for "Looking for help with orbit/follow player script vector math calculations"
http://answers.unity.com/questions/1297326/looking-for-help-with-orbitfollow-player-script-ve.html
The latest comments and answers for the question "Looking for help with orbit/follow player script vector math calculations"Comment by JasonsFreeTime on JasonsFreeTime's answer
http://answers.unity.com/comments/1297364/view.html
Well, just before I checked this post, I managed to figure it out on my own and came up with basically what you provided. Only difference is that no, the object isn't a sphere and rather than use a radius, I am just using an offset float. Although I may look into using an invisible sphere if it's not typical for the root to be at the exact center of the object I'm showing the menu for. I'll have to play with that.
void Update()
{
Vector3 direction = (Camera.main.transform.position - ObjectOfMenu.transform.position).normalized;
this.transform.position = ObjectOfMenu.transform.position + direction * Offset;
}
Anyhow, I really appreciate your response and am amazed at how much I have to learn about this stuff! But I'm glad I didn't give up, pleased with the results, and very very thankful for your help kind person!Wed, 11 Jan 2017 03:38:38 GMTJasonsFreeTimeAnswer by Scoutas
http://answers.unity.com/answers/1297354/view.html
I'll asume the object your menu rotates around is a sphere. It might be little bit more complicated to do, if it is a different object, but we could try and tackle that as well.
First things first - we would need two radius'es. One for the sphere object, one for the menu.
Secondly, we need a Vector3 for a direction of where you'd want to put your menu on.
public class Orbit : MonoBehaviour {
// declare both the sphere object and the menu object
public GameObject sphere;
public GameObject menu;
// declare the radius of both objects (basically in this case, the menu would float 0.2 units above the sphere)
public float sphereRadius = 1f;
public float menuRadius = 1.2f;
// the direction that we need
Vector3 dirVector;
void Start(){
// let's make the sphere have the radius that we set
sphere.transform.localScale = Vector3.one * sphereRadius;
}
void Update () {
// to get the direction that the menu has to be on the sphere, we need to
// subtract the sphere objects coordinates, from the camera coordinates
// and afterwards we normalize that vector (so it has magnitude of 1)
dirVector = (Camera.main.transform.position - sphere.transform.position).normalized;
// now we set the position of the menu. From the center of the sphere object, we move it by the radius for the menu we described
// in the direction that we have calculated
menu.transform.position = sphere.transform.position + dirVector * menuRadius;
}
}
![alt text][1]
I hope this is all clear enough. Do tell if you need something a little bit different.
[1]: /storage/temp/85712-help.jpgWed, 11 Jan 2017 03:02:18 GMTScoutas