Game Development Reference
the rocket, it can be done easily without trawling through the rest of
the code. In addition, you can expose them by removing the private
keyword and they will become editable in the Unity Editor's Inspector.
The Move() function is more complex and needs further explanation
In 3D space there are three axes around which an object can rotate. These
rotations are analogous with the rotational movements of an aircraft.
As shown in Figure 2.21 , a rotation about the x axis (b) creates pitch , a
rotation about the z axis (c) creates roll , and a rotation about the y axis (d)
develops yaw .
The angles used to specify how far to rotate objects around these axes are
called Euler angles . Euler angles are often used in 3D software and game
engines because they are intuitive to use. For example, if someone asked you
to rotate around your vertical axis by 180° you would know this meant to turn
around and look in the opposite direction.
However, there is a fundamental flaw in using Euler angles for rotations in
software that can cause unexpected rotational effects. These angles are
applied one after the other and therefore have a mathematical compounding
effect. This consequence is seen in the mechanical devices used to stabilize
aircraft, ships, and spacecraft—the gyroscope.
A simple gyroscope is illustrated in Figure 2.22 . It consists of three discs
attached to the outer structure of a vehicle (in this example a plane) and
attached to each other at pivot points each representing rotations around
the x , y , and z axes. These rotating discs are called gimbals. As the plane yaws,
pitches, and rolls, the gyroscope responds to the forces with the rotating of
the discs at their pivot points. The idea is that a plate attached to the central,
third gimbal remains upright at all times. Navigational systems attached to
the gyroscope monitor this plate to determine the orientation of the vehicle.
For example, if the vehicle were on autopilot, the objective would be to
keep it upright and level to the ground, and any change in the gyroscope's
orientation assists with pitch, yaw, or roll corrections.
A situation can occur in which two of the gimbals become aligned, as
shown in Figure 2.22d . This is called a gimbal lock . At this point, it can either
be corrected with the right maneuver (e) or cause erratic behaviors. In
Figure 2.22f , the third gimbal cannot rotate back such that the central plate
is facing upward, as its pivot points won't allow it. In some circumstances,
alignment of the first and second gimbals can also cause the third gimbal
to flip upside down, even if the vehicle itself is not upside down. When this
occurs, the navigational system becomes very confused as it attempts to
realign the vehicle.