Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
In the Inspector window, Unity displays rotation values using 360 degrees for X, Y, and Z, but that's just so that they're easier for us humans to understand. Behind the scenes, Unity stores rotations as a mathematical object called a quaternion. Unity provides methods for working with quaternions so that we can rotate 3D objects.
Unity Documentation

Quaternion  Quaternions are mathematical objects that represent a 3D rotation. In Unity, the
Quaternion
class has many useful methods and variables.

0:00
The frog character can move left and right, but

0:03
it also needs to rotate and face the direction it's moving in.

0:08
Rotating an object in Unity is slightly more complex than changing its position,

0:15
but Unity includes special rotation methods to make it easier.

0:21
In Unity, the transform component only shows us the x, y, and

0:25
z values for position and for rotation.

0:29
We can manipulate the values for position directly in our code, but

0:34
we cannot change the values for rotation in the same fashion.

0:39
Mathematically, rotating an object in

0:41
3D space is much more complicated than it may appear.

0:45
In the inspector window, Unity displays rotation values using 360 degrees for

0:51
x, y, and z; but that's just so that they're easy for use humans to understand.

0:57
Behind the scenes,

0:59
unity stores rotations as a mathematical object called a quaternion.

1:04
Unity and just about every other game engine uses quaternions instead of XYZ

1:10
values because they solve a lot of issues with 3D rotations.

1:15
For example, if we were to directly manipulate the X, Y, and

1:20
Z rotation values of the frog character, it might seem fine at first.

1:25
Over time however, or in specific situations, bizarre problems can arise.

1:31
The frog might rotate in a direction that's different than what we expect.

1:36
Or, it might get completely stuck and won't rotate at all.

1:41
The good news is that you don't have to understand the math of quaternions to use

1:46
them in Unity, because Unity has built in methods for working with quaternions.

1:52
In fact, most game developers, myself included, don't fully understand the math

1:57
of quaternions, but quaternions are still used all the time.

2:01
It might seem strange to not fully understand the inner workings

2:04
of the methods that we're using, but it's best to think of them like an appliance.

2:09
I don't understand all of the inner workings of my refrigerator or my car, but

2:14
I still use them all the time.

2:16
Similarly, Unity provides methods for working with quaternions so

2:21
that we can type in our code and

2:23
get a result without possessing an advanced degree in mathematics.

2:27
Using quaternions will solve all the strange problems we might encounter if we

2:31
tried to directly manipulate rotation values.

2:37
Now that you have some idea of why we're using quaternions instead of normal

2:42
XYZ rotations, we're ready to learn about quaternion methods

2:46
that will help us rotate the player character so

2:49
that it's facing the proper direction as it moves around.
You need to sign up for Treehouse in order to download course files.
Sign up