Different Value in Inspector and Code

Hi Dear Experts! :smiley:

I have a question for you please:
I have a cylinder in a game scene, which revolves around itself by hitting UpArrow key.
I have a logic based on current value of its rotation, but reading its transform.rotation in code, returns strange numbers.
To explain more, when I run the application and select the cylinder in the editor and watch the rotation values, it changes from (x, y, 0) to (same x, same y, 360), because I’m revolving it around z axis. This is very desired and reasonable.
But when I add print(this.transform.rotation.z.ToString()) to Update method, it strangely returns a number between -0.7 to +0.7, which is not even radian, right? Radian should be between (0, 2 x pi).

So, what’s the problem and why the code result is so different from the inspector?
Thank you very much :slight_smile:

This is because in Unity, rotations are represented as Quaternions. These are a way of describing rotation using 4 numbers instead of 3, to get around the problem of Gimbal lock. With Unity’s Quaternion value, the “z” value you’re reading is not the rotation in the z axis, but a different value altogether. To read off that value, you need to use the eulerAngles function, to get the commonly understood rotation vector.