Math in Unity : Vectors (Part I)

Before we move on, we need to understand this :
what is a Vector?

If I said that a Vector is a point in a Cartesian plane, would that be right?

For example, if in any 2D project I create a sprite, and put it in this position:

Vector 2, 3, 0 will be the position of the sprite.

BUT there is a difference:
in this case, for example, 2, 3, 0, represents a POINT shifted by 2 on the X axis and 3 on the Y axis, starting from
the ORIGIN POINT, 0, 0, 0.

A Vector, on the other hand, can start from anywhere in space, and its measure will be: 2 on X and 3 on Y.
Furthermore, it will no longer represent a point, but a DIRECTION, and its MAGNITUDE will be given by its length.

It is usually represented like this, with an arrow indicating the direction

How do we calculate the length of a Vector?
With the Pythagorean Theorem.
The formula is this:

|| v ||
is the mathematical notation for the length of a vector.

In this case our equation is
square root of (2 * 2) + (3 * 3)
4 + 9 = 13
square root of 13 is 3.60
and this is the LENGTH of the vector 2, 3, 0.

Having a Vector, and knowing its point of origin, we can calculate its destination simply by making the SUM of the two Vectors.

To give a simple example, if our Vector 2, 3, 0 started from the point
0, 0, 0, its destination will be 2, 3, 0.
If the starting point were 6, 3, 0, its destination will be 6, 3, 0 + 2, 3, 0
the result is 8, 6, 0.

In both cases, the DIRECTION and the LENGTH of the Vector are exactly the same.

I wanted to talk about these little basics regarding the Vectors, because in videogames we will have to deal with them many many times.
It is not necessary to have a complex mathematical background to be able to program video games, but since some formulas or concepts will always be present, I think having a basic idea can be very useful.

In the next articles we will look at the Vectors in more detail, with less theory and more practice in code.

Always in love with programming, even if late (I'm already 39 years old) I decided to follow my dream! We will see how far my passion will take me!