Game Development Reference
In-Depth Information
that you can always refer back to when needed. As you work your way through this section, don't
get hung up on the math. While I remember fondly my time at CalTech having to hand-jam vector
calculations, you won't have to—Unity will handle this for you. For now your focus should be on learning
the vocabulary and visualizing vectors and their functions in 3D space rather than the math itself.
Unity uses the Cartesian coordinate system for describing points in space using an x axis and y axis
that are perpendicular to each other (Fig 2-29 ). The origin is the point where they intersect, defined
where both the values of x and y are zero or (0, 0). Every unique point in 2D space can be described
by its x and y value using the syntax (x, y).
y
(-3.5, 3)
(3, 2)
(0, 0)
x
(1, -3)
Figure 2-29. The Cartesian Coordinate system
The variables that you've used up to this point—int, float, boolean, and string—are classified as
value data types because they contain a specific value such as 8 , hello , or false . A more complex
version of a value type variable is known as a structure , or struct . A struct is a variable containing
an aggregate of values.
Vector2 is a struct that contains the x and y values to describe positions and vectors in two-dimensional
space. (x, y) gives you the location of a point in 2D space. To describe a line or vector you would
normally need to know the coordinates for the points at both ends of the line, but in Unity vectors are
expressed as lines relative to the origin (0, 0), so (x, y) is enough information to describe the vector as
well (Fig 2-30 ).
Search WWH ::




Custom Search