transform.Rotate is returning unexpected results
Hello, I have a question. I probably missing some basic knowledge, because I do not understand following scenario:
I have an object, whose rotation is [0,0,0]. Then I run following 2 commands:
transform.Rotate(45, 45, 0);
transform.Rotate(-40, -40, 0);
Result is rotation = [-2.268; 15.476; -27.057] I would expect something like: [5;5;0] Thanks
Answer by Hellium · Jan 26, 2018 at 09:44 AM
If you take a closer look at the documentation, you will read the following:
Transform.Rotate
Description
Applies a rotation of eulerAngles.z degrees around the z axis, eulerAngles.x degrees around the x axis, and eulerAngles.y degrees around the y axis (in that order).
If relativeTo
is not specified or set to Space.Self
the rotation is applied around the transform's local axes.
So, the applied rotations are:
+45° local X axis
+45° local Y axis
-40° local X axis
-40° local Y axis
The result can't be (5°, 5°, 0) because the rotation are applied to the local axis in the order XYXY. However, if the rotation would have been applied in the XYYX order, you would have a final rotation of (5°, 5°, 0°)
@Hellium thanks for your answer. It makes sense to me if I simulate it step by step. It's very difficult to calculate and imagine from top of my head though. Especially mixing both world and local coordinates. Is there any hint? Thanks
I don't have any tips unfortunately, and I think you have no choice but calling transform.Rotate
multiple times to have the "step by step" process if you want to get back on your feets.
Your answer
Follow this Question
Related Questions
how to to rotate a object in 2D to known position values 0 Answers
How do I fix popping eyes (popout of the model) 0 Answers
Camera self rotation script problem 1 Answer
How *not* to fly completely upside-down (Drakengard-esque) 0 Answers
Rotation anchor won't move with prefab,Rotation anchor problem 0 Answers