Game Development Reference
In-Depth Information
Three-dimensional space is handled much the same way, but with the value representing the third
dimension added to the mix. The z axis is perpendicular to the x axis and y axis. In Unity, they are
oriented such that x is laid out horizontally left and right across your computer monitor, y is vertically
up and down on your monitor, and z is depth, or “into” and “out of” your monitor. Put another way,
the xz plane is the “floor” and y is altitude. The origin is (0, 0, 0), representing the values of x, y, and
z. In Unity this is also referred to as world zero —the center of your game world. Just as you saw in
2D space, a vector in 3D space is also expressed relative to the origin (Fig 2-37 ):
(4, 5, 3)
y
(0, 0, 0)
x
Figure 2-37. A vector in 3D space
Vector3 is a struct that holds the values for x, y, and z. Look up Vector3 in the Unity Scripting
Reference, and you will find that it closely resembles Vector2 with handy, commonly used static
variables, the x, y, and z component and vector magnitude values, and many of the same functions
and operators.
To compare, take a look at Vector3.magnitude in the Unity Scripting Reference (Figure 2-38 ):
Figure 2-38. Vector3.magnitude description in the Unity Scripting Reference
Search WWH ::




Custom Search