The Why Behind the What. The Skills You Need to Learn to Make Video Games: Part 2

Drew Coleman
8 min readMay 22, 2019

--

Photo by Emily Morter on Unsplash

In my previous blog post I discussed why we need to know certain skills or learn certain subjects in order to become a successful game developer. I believe knowing why we need to do something is important because it can be a source of motivation or at least prevent us from wasting our time.

If you are interested in knowing why you need to know about C++, algorithms, data structures, and computer hardware then check out my previous post here, otherwise stay here to learn all about why maths is so useful to game developers.

A bit of forewarning. I am not intending to go into any specific detail about any of the subjects I cover in this article. I want to do my best to describe each topic just enough so you can see its relevance in video games, I am assuming that readers might already have some knowledge when it comes to things like trigonometry and algebra. Instead, I just want to show that maths as a subject plays a huge role in the development of video games, giving examples of exactly why that is the case.

Numbering Systems

Numbering systems are a way of representing numbers. You should be familiar with the base 10 system where numbers are represented from 0 to 9 as that’s what we use in everyday life. When it comes to programming you will come across a few different numbering systems such as binary and hexadecimal.

Binary is the language computers understand, 1s and 0s, with these numbers referring to electric signals in the computer either being on or off. Whether or not we are processing instructions with the CPU, or storing data on a hard drive, it all ends up being a bunch of 1s and 0s.

As everything is a 1 or 0 we have to give meaning to a combination of these numbers. For example, we could say that the following binary number 1111 1101 1010 1111 0101 1001 represents a number, or it could also be used to represent a colour. The specifics of how this works isn’t important for now, just remember that everything ends up being represented as 1s and 0s.

The problem with binary is that it is easy for the computer to understand, but less so for human beings. That’s why alternative numbering systems have been used in computing to provide a shorthand for representing binary.

A good example is if you look at any photo or illustration app. You will usually be able to select a colour using a hexadecimal value such as #FF006112 which is a shorthand for representing the red, green, blue, and alpha (opacity) of a colour. The more 1s and 0s we use to represent our colours the greater the spectrum of colours we can represent because we would have more numbers to represent different colours. The problem is that the above hexadecimal value in binary is 1111 1111 0000 0000 0110 0001 0001 0010 which is a lot more of a pain to type into your photo editing program than the hex values.

Therefore, it’s good to understand numbering systems so you can understand any values you see in code that are not written in the standard base 10 number system. Additionally, having a good grasp of binary (base 2 numbering system) and operations you can perform on binary numbers (bit-wise operations) can help make your programs more efficient.

Algebra and Basic Arithmetic

Basic arithmetic and algebra are fundamental to mathematics so it’s not surprising that they are also important in game development. Arithmetic allows us to manipulate numbers, and algebra allows us to manipulate variables that are used to represent numbers or groups of numbers.

To give an example, say we wanted to create a damage system for an RPG game of ours. If we have a player whose health starts at a 100 and every time, they are hit by a goblin they take 15 damage. We take the damage from our current health, to get the new health of our player.

newHealth = currentHealth — 15

If we had more than one enemy type in our game, or if our goblins somehow got stronger then we might want to replace 15 with a variable called damage that represents the damage any character can deal to us.

newHealth = currentHealth — damage

Now let’s say we want to add suits of armour to the game that the player can collect. Each suit of armour has it’s own resistance to damage, so when wearing armour, we can make it so the player takes less damage.

newHealth = currentHealth — (damage/ armourResistance)

If our armour resistance is at 1, we receive the full damage from the enemy, if it’s at 2 we receive half the damage, at 10 we receive a 10th of the damage and so forth.

This example is rather trivial, but I hope it shows that even with a basic understanding of arithmetic and algebra you can use maths to help you design certain gameplay systems within a game. There are countless things you can do with these simple concepts.

Trigonometry

Whether you love it or hate it, it’s hard to avoid using trigonometry in game development. Trigonometry is all about triangles, the lengths of sides of triangles, the ratios between the sides of triangles and the angles of triangles. It’s all about triangles.

A simple example of how we can use trigonometry in games is when we want to find the distance between two objects in our world. Imagine we have two characters and we want to find out if one of characters is a specific distance away from the other so that they can start attacking them with some ranged weapon.

Given that we know the coordinates of the player, and the enemy we can form a right-angled triangle, calculate the length of the sides of the opposite and adjacent sides and then from there we can then calculate the distance between them using Pythagorean’s theorem.

(approximately 6.4)

Again, this is just a simple example of how trigonometry can be used in game development, but it has a lot of other uses. If we wanted to make sure our character was facing the other before attacking, we would could rotate our character which would also require using trigonometry.

Geometry

Geometry is defined as the branch of mathematics concerned with the properties of points, lines, surfaces, and solids, with some of the most obvious uses cases of geometry in games relating to the visualisation and the less obvious, interaction of objects.

Whether 2D or 3D, the objects we see in games from characters and buildings, to water and trees, are all described using some geometric shapes amongst other things. From a visual standpoint much of the geometry is handled by artists and imported into the game. Game developers are more concerned with making sure the geometry is displayed correctly and is interact-able.

Note: although it is also possible to write beautifully procedural generated worlds from sets of algebraic equations like this.

What I mean by interact-able, is that like in the real world if I was to drop a basketball from a height onto the ground, we would expect the ball to hit the floor, and then bounce back up again.

Geometry is needed in games to mimic this kind of behaviour. The objects in our games are only defined by their physical appearance, a set of points that describe their shape, and if we want to add in behaviour such as simulating a ball hitting a floor and bouncing back up we have to do that ourselves with code.

Typically, we would use simple shapes, like a plane to represent the ground, and a sphere for the ball, so that we can do efficient intersection tests to see if the ball has collided with the plane. If we know this, we can then code how we want the ball to interact. Using geometry to test for intersections in video games is known as collision detection and makes up a huge part of how physics engines work.

Linear algebra

Linear algebra is not something you can easily ignore as a game developer as certain aspects of this topic provide the foundations for how we are able to see create and display 3D worlds onto the 2D rectangles that are our computer screens.

Linear algebra is a large subject, with only a subset of it used in video games, for this article I will focus on just three smaller sections of linear algebra that come up most frequently in game development: vectors, matrices, and transformations.

Vectors

Example of Vectors with different directions and magnitudes

Vectors allow us to represent magnitude, the extent or size of something and direction, where that magnitude is being directed towards. Graphically, a vector can be represented as an arrow where the place where the arrowhead points, describes it’s direction, and the length of the arrow refers to it’s magnitude. We can carry out operations on vectors like how we would with normal numbers, such as adding and subtracting, as well as performing unique operations, like the dot and cross product.

Vectors can be used to represent all sorts of important things such as velocities, forces, points, and distances. A brief list of some of the things you can do with vectors:

  • Move an object in a certain direction
  • Find the distance between objects
  • Apply a force to an object, such as gravity
  • Find the direction in which an object is facing
  • To handle collisions between objects
  • Calculating the amount of light that hits an object
  • And so much more!

Matrices & Linear Transformations

Example showing two different matrices

You can think of a matrix as a grid of numbers which like with vectors, we can perform certain operations on such as addition, subtraction, and multiplication. Matrices are great for allowing us to represent linear transformations.

A linear transformation is a function that allows us to perform certain actions on our objects, like moving them, rotating them (with the use of trigonometry), or scaling them. Putting our linear transformations into matrices allows us to use them in a more efficient way.

Therefore, matrices are used in video games, specifically within computer graphics to represent linear transformations, and are used to apply transformations to our game objects but to also apply transformations that take the position of an object within a game world and translate it to a location on our 2D screen. Taking an object made up of 3D points and allowing it to be represented by coloured pixels at a specific location on our screen.

To conclude, I realise that this article might not have been overly useful for anyone looking at actually learning about any of these topics that I discussed, but I hope instead, that you come away with an understanding of just how important maths is to video games and thus to the anyone looking to make games.

To read me more check out my blog at: www.gamedevunboxed.com

--

--

Drew Coleman
Drew Coleman

Written by Drew Coleman

Game developer writing articles about: game development and programming.

No responses yet