- Home /
How to prevent transform.Rotate from oddly flipping other axis...
I am having a really weird issue with an extremely simple thing.
` if (Input.GetKey(KeyCode.D)) { rocket.transform.Rotate(30 * Time.deltaTime,0,0); } `
When I run this it turns my rocket just fine, however, as I turn, when I reach 90 degrees it suddently and for no appearant reason flips z and y to 180 degrees as indicated by the inspector and evident by the output of eulerAngles. Why does it do this and how can I stop it?
Answer by Eric5h5 · Sep 04, 2012 at 10:26 PM
You can't stop it; that's a side effect of Unity storing rotations as quaternions. There's more than one valid way to represent a quaternion as euler angles. This isn't an error or anything; everything still works as expected. For example, (0, 0, 0) is the exact same rotation as (180, 180, 180).
So what is the best way to get a useful angle value to use in $$anonymous$$athf.Sin then? I made a script that makes an rocket move in a direction deter$$anonymous$$ed by the angle of the rocket and the total thrust.
The problem appears when I go below horizontal, like trying to crash the rocket into the ground. Ins$$anonymous$$d of crashing it flies up because the object got flipped.
I am using sin and cos to deter$$anonymous$$e what portion of the thrust is in what direction and eulerAngles to give it that angle, but that angle is wrong for anything below horizontal.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080632im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Problems caused by non-unique Euler angle solutions 1 Answer
How to set an exact Local angle. 0 Answers
Instantiating an object in front of the player 3 Answers
How can I change rotation of parent independently without affecting angles and rotation of child ?? 2 Answers
Precise rotation based on joystick axis input for twin-stick controls 3 Answers