Basic Game Math: Vector Addition

Development1 min read

Usually, this is used to move object position to other position by some vector that represents directions in game object movement. Like if you want to move the object to some direction using vector or push object to the x-axis or anything.

To do this, you just need to add both vector and the result is final position. Here’s the equation:

vec3 = vec1 + vec2

Which can be expanded to:

vec3.x = vec1.x + vec2.x

vec3.y = vec1.y + vec2.y

Adding a vector is like put the tail of the second vector on the head of the first vector without changing both vector direction. See image bellow:

Vector-Additions

An easy example for that is when you want to move a game object from one vector location to another vector location. For example, you have an object that has position in vector a, let’s say Vector2(3,4). You want to move it to the right direction following a x-axis by one point (Vector2(1,0)).

finalPosition = position + direction

finalPosition = Vector2(3,4) + Vector2(1,0)

finalPosition = Vector2(4,4)

Easy right? And just like normal addition. There is no difference between (a+b) or (b+a).

And just like normal addition. There is no difference between (a+b) or (b+a).

For 3 dimensional vector, you can use the same equation but with an additional axis.

vec3 = vec1 + vec2

vec3.x = vec1.x + vec2.x

vec3.y = vec1.y + vec2.y

vec3.z = vec1.z + vec2.z

And that it for vector addition. If you have any question, you can ask on the comment bellow. Have a great day.