- Home /
Rotating Object on its Local World Axis
I have been trying to rotate my player along its local world y axis. I'm talking about a world object, with no parent, with the local axis handles. I want to rotate around that y axis. How would I achieve this?
Answer by SonicFan · May 30, 2015 at 11:35 AM
Did you try transform.rotate.
public float RotateSpeed = 100;
// Update is called once per frame
void Update () {
transform.Rotate(0,Input.GetAxis("Horizontal") * RotateSpeed * Time.deltaTime , 0);
}
if you want to know more about check the docs here. Hope this helps.
I think this is what you want
public float RotateSpeed = 15;
void Update () {
float rotY = 0;
rotY += Input.GetAxis("$$anonymous$$ouse X") * RotateSpeed;
transform.Rotate(0, rotY , 0);
}
I hope it works.
@SonicFan right that rotates on the local up vector but it still rotates after you stop moving the mouse.
Answer by tanyanzhi · May 30, 2015 at 11:36 AM
you can use Rotate method like this:
void Update() {
transform.Rotate(Vector3.up * 10 * Time.deltaTime);
}
and the default relativeTo is Space.Self
Answer by Eno-Khaon · May 30, 2015 at 09:10 AM
There's a bit that's tough to understand about your question due to some conflicting language, but I'll do my best to offer as much and as thorough of answers as possible.
First off, the confusion comes from the statement of "Local World Axis" -- Local and World are very different from each other, so it doesn't make a whole lot of sense reading that.
The World rotation is relative to the environment. Up is up (Y-axis), north is north(Z-Axis), east is east(X-Axis), and so on.
The Local rotation is relative to individual objects. The object's up is its personal "up" (Y-axis), its forward is its' forward and nothing else's (Z-axis), and its right is its own as well (X-axis).
Anyway, to switch which axis you rotate an object on in the editor specifically (addressed in response to "local axis handles"), you can either press "X" in the scene view to toggle between local and world manipulation (excluding scale, which is modifiable on local scale only), or you can find the button to toggle it near the top of the window by default.
@$$anonymous$$o $$anonymous$$haon should have mentioned that this is by script.
Your answer
Follow this Question
Related Questions
Quaternion.Slerp on local axis 1 Answer
change just z axis angle 1 Answer
Move object relative to its axis 2 Answers
how to get the absolute direction? 1 Answer