- Home /
Rotate object in 2 axes
So why is this happening and how do I fix this? I need to use relative rotation (relative to the camera and RotateAround functions work fine for that) in arbitrary order.
So, for example I press 'W' and object rotates X 20, I press 'D' and object rotates 20 Z. But when I do it other way around I've got strange result, please help т_т
Answer by Narc0t1CYM · Apr 11 at 05:50 PM
It makes sense, because transform.Rotate()
's 4th parameter is set to Space.Self
by default, which means it will transform along the local axis. When you rotate by the Y axis first it doesn't change much for the object - because I suppose that it's already standing vertically - and then doing a Z rotation will achieve what you want. But when you do the other way around - and I still suppose your object is standing vertically - rotating by Z first will rotate by the local Z axis and then it will rotate along the local Y which will rotate all the other axes as well, because when the second rotation happened, your object was not vertical anymore.
Try this:
transform.Rotate(0, 0, 20, Space.World);
transform.Rotate(0, 20, 0, Space.World);
Your answer

Follow this Question
Related Questions
Snap the rotation of object 2 Answers
How to rotate the planar region to alway face the camera? 2 Answers
How do I rotate on a new pivot point with RotateAround? 2 Answers
XYZ Rotation Matrix 1 Answer
Switch Vector3 direction 1 Answer