I am trying rotate a game object around another game object that moves but always maintain the same distance from the moving object. For example, a moon circling a planet. When the planet moves the moon should circle but maintain the same distance. I found this code for rotating around an object but when the "earth" moves the "moon" gets pretty far away.
`var degrees = 10; var target : Transform;
function Update() {
transform.RotateAround (target.position, Vector3.up, degrees * Time.deltaTime);
}`
Any ideas on how to maintain the same distance?
Revised Code:
var rotation : Quaternion;
var radius = Vector3(5,0,0);
var degrees = 10;
var moonCurrentRotation = 0.0;
function Update(){
moonCurrentRotation += degrees*Time.deltaTime;
rotation.eulerAngles = Vector3(0, moonCurrentRotation, 0);
transform.rotation.eulerAngles = Vector3(0, moonCurrentRotation, 0);
transform.position = rotation * radius + EarthController.earthPosition;
}