Vectors in games Part 1

Vector’s are one of the most used tools in games. At first glance it might seem like there is a lot of magic that goes into them but actually they are very simple structures.

Here is an example of a two dimensional vector:

1
Vector A: 0, 2
Vector A: 0, 2

It only has two pieces of data! 0 is the position on the x-axis, 2 is the position on the y-axis.
If we take another two dimensional vector:

1
Vector B: 1, 4
Vector B: 1, 4

We can have a look at some of the basic operations, add and substract.

Addition:
A + B

1
2
3
4
5
0, 2
+
1, 4
=
1, 6
0, 2
+
1, 4
=
1, 6

If you read it column by column you can see that it just adds the x of the first vector to the x of the second vector and on the other set of numbers it adds the y’s together.

Substraction:
A – B

1
2
3
4
5
0, 2
-
1, 4
=
-1, -2
0, 2
-
1, 4
=
-1, -2

This is really how simple vectors are at their heart. In Part 2 we will look at how the length of a vector is calculated and what different types of vectors there are.