Euler angle, quaternions

Greetings,

I read some topics about those, in the Unity forum, and I read the documentation about the Transform component, and I just realised something (maybe) :

  • In the Inspector, the rotation value are euler angles (because there are three value, not four) ? But when we retrieve it, with transform.rotation, we get a quaternion instead ?

  • So when we want to give a transform.rotation specific euler angle, we need to convert them first ? (Quaternion.Euler) ?

  • And from quaternion to euler angle ? Quaternion.eulerAngle ?

  • Gimbal lock, this was mentionned in a previous topic. I went on wikipedia to read more about it and I found these images :


But isn’t it impossible ? I mean, when you rotate something in Unity or anything else, the X, Y, or Z axis should not change like this : no way ! For example, you pick an object in Unity, you select Rotate, you will see the three circle, representing the three axes of rotations, but no matter what your rotations are, you will never get a “gimbal lock” (at least, you won’t see that in Unity)…?

All rotation are handled in Quaternions.

Euler angles are just there as helpers, since Quaternions are only for advanced civilizations from outer space :slight_smile: (or at least they look like that to me!)

So yes, if you want to set a rotation, you’re better off using:

transform.rotation.eulerAngles(x, y, z);

I don’t know about the Gimbal Lock.

First of all, the ‘transform’ component has multiple fields that deal with orientation, including local and global fields for Euler angles and quaternions, respectively. So, you can work with the transform’s orientation in Euler-angle or quaternion form, as you prefer (and as the circumstances require).

Regarding the ‘gimbal lock’ images you posted, gimbal lock doesn’t actually mean that the basis (i.e. direction) vectors get knocked out of orthogonality. All it means is that with Euler angles, certain Euler-angle sequences will remove a degree or rotational freedom. (Whether this is a problem or not depends on the circumstances.)