# Algebra In Video Games

Algebra is heavily used in the process of making video games. Elementary Algebra, Linear Algebra, and other forms of Algebra are needed to build most of the video games that you play.

In this article, I will be listing some of the major game development areas that require algebra, and hopefully give you an idea of how deeply integrated algebra is with the tools that game developers like myself use on a daily basis.

Algebra is used in physics engines, animations, collisions, graphics, game progression, NPCs decision making, and in many other fundamental game development areas. Shooting bullets in FPS games, jumping in platformer games, and roaming around looking for loot in an RPG are all game mechanics that involve algebra.

With all that said, let’s dive into more details into each of the mentioned cases.

## Where is algebra used in video games?

### 1- Algebra is behind the movement of almost all game objects.

Movement in video games is basically changing the position and the rotation of an object/character over a number of frames.

This requires extensive use of motion equations, 2D and 3D vectors, Forces and so on.

One simple example is applying gravity to game characters. If a game developer wants a game character to hit the ground after jumping (they probably want that), then they’ll need to apply the gravity equation on the character if they are looking for realistic acceleration.

They will also need to apply a different custom equation if they want custom gravity behavior.

If they want their character to shoot bullets,  they’ll need the projectile motion equations, and so on. To put it in simple words, algebra powers almost all objects movements in a video game.

Since many use cases of algebra are widely common across many games, some of them come as a package for the game developer to use without worrying too much about the math details.

For example, Physics engines can handle forces, gravity, collisions, velocities and so much more on behalf of the game developers who just want to focus on building their games without worrying too much about complex math.

However that doesn’t mean that these developers won’t need any algebra skills. Algebra is a vital part in a game developer’s life.

Matrices are another great math tool for video games. Linear Algebra is a huge part of the logic behind object positioning and movements in the game world.

Matrices can be used to store the position, rotation, and scale of game objects, and their position relative to each other and to the world origin, and this makes them an integral part of video games.

### 2- Algebra is used in video games animations

A lot goes into bringing the characters to life. A solid character that doesn’t move any of its body parts might not be the best idea for a video game (or maybe yes? Who am I to judge!)

Animating players, monsters, pets, trees, and so on is vital to every video game, and it is no surprise that animation involves a lot of algebra math behind the scenes.

One example is the usage of interpolation (equations that estimate the unknown values in between known values) .

Animators usually create key poses/frames, and then the software used interpolates between these key frames to create the smooth and continuous motion that you see in video games.

### 3- Algebra is used in collision detection and prediction

Collision detection is a very complex subject when it comes to game development.

Engine developers will need to allow the game to detect when different world objects have hit each other, and let the game react accordingly.

This requires a whole lot of complex math, and some of the math involved is related to algebra.

For example, one of the simplest usages of algebra in collision detection is the distance equations. The collision detection algorithms will need to determine distances between polygons, centers, and other points in space.

This requires the use of the distance equations, and hence algebra, since algebra is all about equations with variables.

Motion equations can also be used to “predict” when objects are going to collide together. If the game engine knows the equations that are being used to move 2 objects, and they know all the variables needed to be known, then the engine can calculate when the objects will collide in the future.

These are just some simple use cases of algebra in collision detection, and they are meant to just give you a general idea of how much algebra is involved.

### 4- Game progression can use algebra

Game progression is one of the most important areas of game design. Deciding how the difficulty in the game progresses, how many coins the player gets, how the score is calculated and so on are all part of the overall game progression of the game.

It is no surprise that game progression requires a lot of algebra.

The score of the player in an endless runner game can be a great example. In general, the longer you survive in the game, the higher your score increments will be.

One example of a very simple equation to use to calculate the score in such a game is this:

``scoreIncrement = baseIncrement + (current level * levelIncrement);``

The base amount is the minimum increments that you get, and then as you reach higher levels, your increments start to grow.

Again, this is just a very simple example for demonstration only. Things can get pretty complex when it comes to score calculations, game economy calculations and so on.

In summary, game progression is all about finding the right progression equations for the game including game difficulty, player score, game economy and more.

NPCs (Non player characters) are a huge part of many video games. A game with no other characters except the player can feel dull and empty.

There is a lot that goes behind the addition of NPCs in video games. For example, decision making is one of the things an NPC has to do in video games, and algebra can get involved in this area.

One of the most basic decision making logic is calculating the distance between the player and the NPC, and then deciding what the NPC does.

For example, if the player is within the shooting range of an NPC, the NPC decides to aim and shoot, else they can just decide to roam around.

As you might have guessed, calculating distances (distance equations), shooting weapons (projectile equations), following paths and roaming around (curve equations) are all related to algebra.

Decision making equations can be much more complex than just distance calculations. Variables like player health, player level, NPC health, NPC level, NPC abilities, cooldowns, NPCs count and coordination and so on, can all be part of the equations that decide what an NPC or an AI does in a video game.

In summary, NPCs in video games evaluate a bunch of equations, and the results of these equations decide the NPCs’ course of action.

Conclusion

There are many more examples that demonstrate the importance of algebra and linear algebra specifically in video games. However, I simply can’t list them all because I’ll end up writing a book instead of a quick blog post.

However, I believe that the above list is more than enough to give you an idea about how algebra is used in the making of some of your favorite video games.

If you would like to read more, there is a very similar article on this blog that discusses calculus and its use in video games. Check it out over here.

Here are other articles that you can read if you have enough time and energy: