# 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$

This can be expanded to:

$c.x = a.x - b.x$ $c.y = a.y - b.y$ $c.z = a.z - b.z$

By subtracting a vector with vector, the result you get is vector direction from vec2 to vec1. See image:

So if you do this equation:

$c = a - b$

In vector c, you can get vector direction form vector B to the vector A.

And if you want to do subtraction on a 2-dimensional vector, you can do with the same equation. Except with less axis. See bellow:

$c.x = a.x - b.x$ $c.y = a.y - b.y$

And one last thing. Just like usual subtraction, you can’t switch between A and B.

$a - b \neq b - a$

So be careful when doing a vector subtraction.

And that it for now. If you have any further question or suggestion, you can write them on the comment section bellow.

#### 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 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...
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 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...