I’m trying to create a moon/planet/sun orbit of sorts but am having some trouble. Here’s what I have so far:
{
public Transform planet;
public Transform moon;
void Update ()
{
planet.transform.RotateAround(Vector3.zero, Vector3.up, 5 * Time.deltaTime);
moon.transform.RotateAround(planet.position, Vector3.forward, 90 * Time.deltaTime);
}
}
I have the moon parented to the planet, so it orbits the sun ok. However, it orbits the planet on one axis like this:
[6653-screen+shot+2013-01-13+at+6.56.07+pm.png|6653]
As you can see it looks ok on the left and right, but as the moon approaches the top and bottom it’s still orbiting the planet on the same axis, making its orbit wonky. How would I go about coding it so that the moon is always facing the sun?