Basic Game Math: Vector Subtraction

Development<1 min read

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:

Vector-Subtracts

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.