+91 9591117915 info@pixtell.net

## Math for game developers – character movement with vectors

Pixtell Labs gamedev, Tutorials Math for game developers – character movement with vectors

# Math for game developers – character movement with vectors

Posted By Kirti P

This is the first of the series of tutorials on how to do character movement anywhere on the screen using Vectors. So essentially we are going to learn vectors, which are used everywhere in video games and are very important.

Lets say you have a character (ex Pacman) on the screen and you want to move him across your screen along to the right.

In PHYSICS: We can consider this as the velocity of Pacman. Velocity is represented by $\vec{v}$. The little arrow on top denotes that $\vec{v}$ is a vector. A vector is an angle and a length denoted by $\vec{v}$=(θ, L). A long vector means the character is moving fast and a short vector means the character is moving slow. $\vec{v}$=(θ, L) is the way vectors are represented in physics.

In game development, the above notation for vectors is difficult to store and so we use the x and y coordinates to represent vectors.

In GAMES: $\vec{v}$=(x, y)

If P(x, y) is the current position of Pacman and P’ is the new position, then P’ is the sum of old position and velocity.

P’= (Px+vx, Py+vy)

P’ is now the new position that Pacman needs to go to !