- Home /
Question about Transform.eulerAngles ?
I tried to get a object's rotation angle by read that eulerAngles variable, so i made a simple test script: rotate a object around x-y-z axis individually with transform.rotate() function, and print the eulerAngles to console. For y and z axis,everything looks just fine,0 to 360. But for x axis, things looks wierd. For a rotation form 0 to 360 degree,it shows a cricle like 0 to 90,then 90 to 0, then 360 to 270 and 270 to 360,what is this ... I can't really understand it. :(
I asked this question several times on Internet, all the big shots told me same thing like "hmm, u should know that 'quaternion' stuff blah blah blah
I do know that ‘quaternion' things a little bit , it's a bit complicated but still comprehensible,nothing like alien technology at all.
Anyway if Unity provided a variable like EulerAngles, it should work properly, that is a vary basic function to a 3D game engine.It works fine on y and z axis, but not for x axis. That can't be a 'functional purpose'.An object rotated around x-axis by 100 degree but represent a 80 degree in it's transform.eulerAngles.x variable, that confused me a lot.
Since the object do know how to represent itself on screen correctly , why can't i get a right eulerangle measure? or where can i get it? Should i work with those Quaternions(x,y,z,w) stuff directly? Should i collect all the rotation in my script manually? Even for those objects controlled by physical engine?
You should really either edit your original question or use the 'comment' button, unless you are really answering your own question
Euler angles do work properly. I already explained that there's more than one valid way to represent a rotation with euler angles; quaternions must be used in order to avoid gimbal lock.
Then is there any way that i can get a proper eulerangle for x-axis in Unity? I DID NOT try to set eulerangle, just want to read it, there is nothing about gimbal lock. If your just try rotate your object inside Unity editor around x-axis, it shows same thing just like what i said. Is that a 'peoper way' to rotate an object?
Answer by Eric5h5 · Jul 19, 2012 at 02:14 PM
Rotations are stored internally as quaternions, and there's more than one valid way to represent a rotation as euler angles when it's converted (for example, 0, 0, 0 is the same as 180, 180, 180). So reading a single x/y/z element of euler angles is not advised.
Thanks Then how can i figure out a object's rotation angle at run time? by degree anyway. I would not like to work with those quaternion things directly.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074406im_/https://answers.unity.com/themes/thub/images/avi.jpg)