Introduction

In Unity you’ll want to change the transforms of your objectinstances quite often. The transform of an object determines its position, rotation and scale (size) in the world. If you want to do anything beyond changing textures on a static scene, there is no way around manipulating the transform. Now, this is hardly a problem when translating (changing the position), or scaling (changing an objects size).

When rotating however, this is becomes a problem when you manipulate eulerangles, the easiest way to understand rotations. You’ll have to deal with Gimbal Lock. (a phenomenon that makes small, incremental changes to rotations makes them go haywire when over a certain point) To prevent this, Unity internally represents rotations as Quaternions. But what are Quaternions?

In this selftuition, I will try to clear both my own confusion about Rotations as well as any confusion readers might have. I will focus only on 3D.

Download

Please download the full tutorial including all sources:

Unity Rotations Tutorial (19 downloads)

Body snippet

Gimbal lock

Gimbal lock is what happens when two of the axes align. (See the screenshot below)

Here, the Y-axis and the Z-axis are aligned. This happened by simply rotating the (red) X-axis 90 degrees. We now have a situation in which rotating around the Z-axis and rotating around the Y-axis have the exact same result. That means we’ve lost the possibility to rotate in three dimensions. When you are interpolating from one orientation to another, this property of using Eulerangles causes the object to rotate in an unpredictable way. Instead of interpolating smoothly between two orientations, it will follow a strange arc because at some point two of the axes align which influences the motion. A visual explanation of this phenomenon can be found under sources (source 3)

End

I hope I have supplied you with enough information to understand rotations, as well as some practical examples you can copy into your own projects. As mentioned in the Introduction, I was really struggling with rotations, not knowing how to properly use them. While writing this article I gained a lot of knowledge on how you use rotations and I hope I have succeeded in passing some of that knowledge on. If you feel like you need some more information or maybe hear it in a different way, please check out the sources linked below.

Good luck with your own Unity endeavors! 🙂

Unity Selftuition – Rotations

Leave a Reply