How do video game characters move?

When I was a kid, a saw an arcade machine near my house. Although I only got to play it a couple of times, I do remember how curious I was with it. My curiosity was not linked to any gameplay but the science behind the games. I was curious how the characters followed the motion of the joystick; how the joystick was able to rotate or move the characters across the screen.

rotateByExample.gif

At the time, I was too small to comprehend the math involved. It took several decades until I was able to understand how game-controllers rotate and move game characters.

If you are interested in how it works, keep on reading.

Space Coordinates

A Space-Coordinate defines the position of an object. Since a game character is made up of hundreds or thousands of vertices, a space-coordinate is assigned to the character, which defines the position of its vertices.

vertexofcharacterwithcoordsystem.png

Mathematically, a space coordinate is defined as a 3x3 Identity Matrix.

However, since a character also moves across the screen, the 3x3 matrix is extended to a 4x4 matrix which contains a translation vector.

spacecoordinatematrix.jpg

The upper 3x3 matrix controls the rotation of the character, whereas the rightmost column determines the position of the character on the screen.

Therefore, the rotation and translation of a game character is defined per the components of a 4x4 matrix.

Rendering

During the initialization of a game, the vertices of a game character are sent and stored in the GPU; the Graphics Processing Unit.

Once a game starts, the space coordinate, i.e., the 4x4 matrix values, is continuously sent to the GPU. Each character's vertex is transformed by the 4x4 matrix right before the character is rendered on the screen.

If the space coordinate matrix is the Identity Matrix, then the character is rendered without any rotation or translation.

However, if the space coordinate is modified, the GPU renders the character as rotated or translated.

 
spacecoordmodified.png
 

Game Controller

The components of the space coordinate are modified when you move a joystick or press a button of a game controller. For example, when the joystick is moved left or right, the upper 3x3 matrix is modified causing the character to rotate.

And when you press a button (or move a second joystick) the translation vector in the 4x4 matrix is changed, causing the character to move across the screen.

 
controllerrotatecharacter.png
 

This is how game controllers control a game character. They directly modify the Space-Coordinate of the game character. There is of course more to it, but this is the gist to how it works.

Hope it helps.