Intro to Quaternions & Euler Angles
Big Words…
Quaternions are simply how Unity understands rotations.
Euler Angles: (Euler: pronounced: oiler) — This is how rotations are presented to us, the developers.
“45 Degrees on the X axis.” is equivalent to saying, “X axis has an Euler angle of 45”.
Using the Rotation tool:
Visualizes the Euler angles or the degree of rotation along an axis.
This is an effective way to present information for both the Unity program and developers.
Now, Quaternions are similar to our degrees of rotation, save for one detail. They have an X, Y, Z, and W degree of rotation. Unity, instead of requiring developers to understand the W degree of rotation, converts the Quaternions to Euler angles for developers to understand. The individual rotations along the x, y, and z axes are the Euler angles along those axes.
When dealing with Euler angles, it’s recommended that we always compute our rotations through Quaternions. Remember: this is how Unity processes angles and degrees.
It’s okay to use Rotation tool in the Unity scene view. However, we do not want to directly modify rotations through Euler angles through code, because of a sometimes-occurring error named Gimble Lock.
Gimble Lock happens when (in a 3-dimensional, 3x-Gimble mechanism) there is a loss of 1 degree. The result is the Y Euler angle and the Z Euler angle may align, causing a “lock” and breaking the rotation.
This can be avoided by computing the rotations through Quaternions. Unity will then present the Quaternion as an Euler angle.
So, what’s Quaternion.identity?
Quaternion.identity is the same as setting the Euler angles for the X, Y, and Z to zero.
Don’t forget to set the prefab in the Inspector:
Let’s test out our script:
If we wanted to instantiate a rotation:
The result:
Let’s take a look at our transform for the enemy:
This concludes the Intro to Quaternions & Euler Angles. In the next article, we will talk about other ways to compute Euler angles through Quaternions.
Thanks for Stopping By.