Interactively moving a game object in a circle

I would like to be able to constrain character movement to a circle around another game object. How do I consrain my game object to a certain radius yet let the player control the movement of the object around the center?

1 Answer

1

If I understand you right, you are looking for something like this:

var rotation : Quaternion;
var radius = Vector3(5,0,0);
var currentRotation = 0.0;
function Update()
{
    currentRotation += Input.GetAxis("Horizontal")*Time.deltaTime*100;
    rotation.eulerAngles = Vector3(0, currentRotation, 0);
    transform.position = rotation * radius;
}

I placed this script on the object I want to rotate around another object but I can't seem to move it at all. Any ideas?

This was it. Sorry didn't realize I had to remove the script and re-add it. Thanks for the help.