The best way to explain this is I'm attempting to make a small model solar system (not to scale or anything complicated, just simple rotation as a learning exercise). There's a sun, a planet, and that planet's moon. The planet orbits like normal, however the moon orbiting around the planet shoots off and makes an extremely large and far-away orbit.
My code is as follows (where "target" is the object being orbited around, and "transform" is the orbiting object itself. Both are "Transform" objects.):
public class RotateAndOrbit : MonoBehaviour {
public Transform target;
public float RotationSpeed = 100f;
public float OrbitDegrees = 1f;
void Update () {
transform.Rotate(Vector3.up, RotationSpeed * Time.deltaTime);
transform.RotateAround(target.position, Vector3.up, OrbitDegrees);
}
}
I'm not sure how to compensate for this or even what my mistake is called, but any help would be appreciated.