- Home /
Rotate around using another objects axis
is the title question possible?
My rotate around code uses the player position but uses it's own axis for the rotation axis. so when the player turns right or left it seems as if the controls change. I figured if I use the players axis I could keep the controls consistent no matter which way the player turns. If there is some better way to approach this please let me know
var Player : Transform; var RotateSpeed = 20;
function Update () { if (Input.GetKey ("z")) // spin the player around the world origin at 'RotateSpeed' degrees/second. transform.RotateAround (Player.position, Vector3.right, RotateSpeed Time.deltaTime); if (Input.GetKey ("x")) transform.RotateAround (Player.position, Vector3.left, RotateSpeed Time.deltaTime);
if (Input.GetKey ("c"))
transform.RotateAround (Player.position, Vector3.back, RotateSpeed * Time.deltaTime);
if (Input.GetKey ("v"))
transform.RotateAround (Player.position, Vector3.forward, RotateSpeed * Time.deltaTime);
}

Answer by Marnix · Apr 14, 2011 at 04:19 PM
Seems like a fair solution to me. Quite clean. You will have to change change your Vector3.right to for example: the players own right. Like: Player.right. I think you can ask that. Or if you want it to be like the camera's axis: Camera.main.transform.right. Play around with the different axis. Just think of: about which axis do I want to rotate this object?
Every transform has its own right, forward, up, etc. You can just call it as the axis you want to turn your object around. Vector3.right is the same as Vector3.unitX, so that is just (1,0,0) always. Doesn't seem like a good one to use here.
Your answer
Follow this Question
Related Questions
rotate object around another object 1:1 1 Answer
Set max allowed angle? 1 Answer
RotateAround 2 axes at once 0 Answers
Rotatearound Collider axis 1 Answer