Basic Game Math: Vector Addition

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:


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.

Want more like this one?

Game Coding Complete, Fourth Edition About 4-5 year ago, when I first started to take game development seriously. I want to know how to properly developing a game. Back then I just code t...
Basic Game Math: Vector Subtraction Substracting vector, like addition vector, is basic and easy equation to do. Since you just need to subtract each axis from both vector. c = a - b T...
Basic Game Math: Vector Multiplying or Dividing In the 2 previous post, which is about vector addition and subtraction. Right now, I will write about how to multiply or divide vector with some numbe...
Basic Game Math: Vector Length In the last couple post, I write about basic Vector operation addition, subtraction, multiplication, and division. Not only that, but I also give an e...