I am developing a solar system animation in Unity3D. Planets rotates around sun. But ı have an issue simulating satellites like Moon. Moon should be rotating around world normally and moon should be rotating around World. Since World is rotating around Sun , i am having trouble about calculating true rotation for moon. I don't want to use rotateAround() since it is deprecated. I need to make this done using Rotate().
this is my planetScript
public class planetScript : MonoBehaviour {
public GameObject target;//target is Sun for World, World for Moon etc
public float rotateRatioCenter;//1 degree for World
private float rotateSpeedTarget;
public float rotateRatioAround;//365 for World
private float rotateSpeedAround;
public float counter = 0;
void Start () {
}
// Update is called once per frame
void Update () {
rotateSpeedTarget = rotateRatioCenter * gameMasterScript.rotateAroundCenterRatio;// rotateRatioCenter * 1 ,
rotateSpeedAround = rotateSpeedTarget * rotateRatioAround;
float yRotate = transform.eulerAngles.y;
transform.Rotate(Vector3.up, rotateSpeedAround);
rotateAroundTarget();
}
void rotateAroundTarget()//this is the method should be optimized
{
Quaternion quaRot = Quaternion.Euler(0, rotateSpeedTarget, 0);
transform.position = quaRot * (transform.position - target.transform.position) + target.transform.position;
}
}