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 answers for the question "Looking for help with orbit/follow player script vector math calculations"Answer 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