Vectors

Today I started looking into vectors within games and how they effect everything.

Traditionally, a vector is a set of numbers used to define a direction and a speed in one go. Every time you move, rotate or scale an object in Unity, you are manipulating a vector.  The position, scale and rotation of your GameObjects are all stored as 3-dimensional vectors. Additionally  a rigidbody will store velocity as a vector.

The number of dimensions a vector has refers to the number of coordinates it stores. Generally speaking, a 3D vector will contain X, Y and Z coordinates.

A 2D vector will have X and Y values.

As vectors are simply sets of numbers, the process for adding and subtracting them is fairly straightforward.

The coordinates in the resulting vector are calculated by applying the arithmetic to the corresponding coordinates in the original vectors. (examples taken from presentation)

{ 1, 2, 3 }   +   { 3, 2, 1 }   =   { 4, 4, 4 }
{ 8, 8 }   –   { 3, 2 }   =   { 5, 6}

Vector multiplication is not as simple. Multiplying the coordinates together in a similar way to addition does not give any really meaningful result.

Vectors can be scaled, however. The process is easy; you just multiply each coordinate of the vector by the scalar value (the number to multiply by).

{ 1, 2, 3 }   x   5   =   { 5, 10, 15 }

 

 

Leave a comment