Transform.Rotate weird behaviour?

Hej community,

I got some weird results from rotating an object along it’s own x-axis (just the x-axis, object is not rotated at the beginning). I rotate the object using

transform.Rotate(Vector3.right, Time.deltaTime * GameTime.Factor);

The strange thing I don’t unterstand is why it’s internal rotation (shown in the inspector) changes when reaching (90f, 0f, 0f) to (90f, 180f, 180f) and then counts backwards again to (0f, 180f, 180f). Can someone explain me this?

Regards
Mexallon

That is probably because Unity uses Quaternions internally.

In the docs, this line sums up why: ‘They are compact, don’t suffer from gimbal lock and can easily be interpolated. Unity internally uses Quaternions to represent all rotations.’

In the inspector of the transform the eulerangles of a quaternion are displayed (Because quaternion w,x,y,z values are not easy to understand).

Sinse you change the quaternion through code, the eulerangles in the inspector are calculated again for the new rotation. And sinse [0,180,180] is actually the same rotation as [180,0,0], you have a high chance that the rotation in euler angles will look weird, as while you are rotating it along one axis, the displayed value is just a eulerangles representatation of the current qaternion.