fbpx

How Video Game Math Works in Game Development

Alexander Brazie

Alexander Brazie

Alexander is a game designer with 25+ years of experience in both AAA and indie studios, having worked on titles like World of Warcraft, League of Legends, and Ori and The Will of The Wisps. His insights and lessons from roles at Riot and Blizzard are shared through his post-mortems and game design course. You can follow him on Twitter @Xelnath or LinkedIn.

A lot of people entering video game design are paralyzed with fear by the M word: math.

While I’m a systems designer and use quite a bit of math myself, in truth, most of the math in video game design is either simple algebra or vector multiplication.

And even if those terms still cause your heart to palpitate, fear not! I’m here to break down these abstract math terms into the actual concepts a game developer thinks about every day.

That’s why some people find it much easier to learn math in the context of video game design than they did at school: all of those abstract variables like X and Y now have specific, concrete meanings.

Now, keep in mind, this website is focused on video game design, not game programming or game math. My goal is to give you a broad overview of many math concepts from the perspective of a video game designer.

For those of you looking for more in-depth views of these topics, I’ve linked to resources throughout this post.

By the way, as you’re reading this post, if you have any questions or issues implementing you can get free help in the #game-design channel in Funsmith Club Discord, or you can DM me there.

Get notified each week on the latest game design tips, guides, templates, and workshops that I don’t share anywhere else here 👇

And feel free to use this ToC to jump to any part of this post 👇

Math in Video Game Development (The Big Picture)

The process of developing video games use a lot of math such as

  • Physics
  • Raytracing
  • Reading and writing to memory
  • Etc.

However, much of that sits in the domain of hardware, game engines, graphics and gameplay programmers.

What’s important to understand here is that the amount and kind of math you need to do depends heavily on the context of your role.

None of this should keep you away from pursuing game design or other roles in game development.

Very few video game developers use advanced math, and if you do end up needing to understand a specific technique, you do what we’ve all done: Google it and read about it on Stack Overflow.

This is particularly true for the many disciplines within game design.

How Do Video Game Designers Use Math?

The type of game design discipline context you choose determines the type of math you need to learn:

  • A quest or narrative designer might never use anything besides basic arithmetic
  • A combat designer needs to compare multiplicative and additive damage multipliers
  • An game economy designer might model hypothetical resource flows and taxation rates
  • A game systems designer might use linear regression and algebra daily when evaluating and adjusting gameplay systems

There’s no mystical curtain of impossible math you have to get through before you can create fun game mechanics.

Video game design is about deeply understanding the emotional experience of the player and crafting journeys for them out of game mechanics.

In fact, Nintendo even specifically encourages their design department to look for new hires outside traditional engineering roles.

How Much Math Is Needed for Game Programming?

I’ll start with the most basic version of this question, one that causes many aspiring designers anxiety: “Do I need to do math to make a game?”

The short answer is no, it’s possible to make a game without being a math nerd.

Video game designers come from all walks of life: math teachers, programmers, writers, chemists, historians, legal backgrounds and far, far, far more.

Hollow Knight and many other successful games were built mostly from simple game-making tools. Engines like Construct and Game Maker are designed to allow novices to create simple games.

Ultimately, the purpose of computers is to do the math for you.

The long answer is no, you will need to use math at some point.

More important than remembering any particular formula, technique or specific set of math skills is understanding the relationships described by math. Game developers are constantly describing the relationships between things.

Even if you have an engine that runs all the physics for you, calculating friction and gravity and bursts of force, knowing how it works is essential to make the game play and feel the way you want it to.

Did you know that most platformers use a value for gravity three times stronger than Earth’s? That’s what it takes for a game to feel right when seen from the side.

Knowing When to Use Math At All

However, there are multiple ways to approach any design problem and math is only one of them.

For example: What if you want to make an explosion do more damage if you’re standing in the center of the blast and less if you’re at the edge?

You could use math:

game math code 1

Or you could simply deal damage twice. Once at the max radius and once again at the inner radius:

game math code 2

The first creates a linear interpolation which rewards every unit of distance you get from the center. The second creates a two-stepped zone, where you take 15 damage in the center circle or 10 in the outer ring.

When I built Xerath in League of Legends, I chose the second approach. I wanted a crisp, clear reward for successfully leading the target. Partial degrees of success beyond this would only frustrate the Xerath player and lead to inconsistent results for the victim.

Making that kind of decision is what video game design is all about. Math is just a tool in your pocket to create different kinds of experiences. It’s not the core of what makes your game successful.

OK, but…

What Math Do Game Developers Actually Need?

As a former programming and computer science major who studied everything up through advanced mathematics and graph theory, I’m going to tell you that the most helpful math is what most of you already learned in grade school.

But as I said, it does vary a lot based on your role.

A gameplay designer should know the following (which is mostly high school math):

  • Basic mathematical operations
  • Algebra
  • Linear problem-solving skills
  • Discrete logic

Someone working on the technical side of gameplay graphics will need to know more:

  • Vector math
  • Trigonometry
  • Matrices
  • Floating-point calculations

And someone creating a physics engine could use a number of technical skills on top of that, most importantly:

  • Calculus
  • Quaternions

I’ll introduce you to all of these in this article (besides calculus), so you have a starting point to understand which of these tools might be useful for your future career or hobby game-making.

Which Math is Most Useful for Game Development Prototypes?

Now we’re at the real question. I’ve built quite a few game prototypes, from simple puzzle games to graphically impressive games to sophisticated networked games.

Here’s some of the most useful math for that purpose:

Vector Math

This is the mathematics of position, direction and distance.

If you come from a games engine background, you might think of the term Vector3 (Unity) or FVector (Unreal), which store 3D vectors as three values (X, Y, and Z).

You can use this to store a particular direction (an arrow) or a particular position in space (a point).

Getting confused about what a specific vector means (direction, position, or both) is a common cause of mistakes.

However, vectors are incredibly useful as long as you keep track of these different uses:

  • Position (a scalar value)
    • Where is the object?
  • Normalized vectors (a direction value)
    • What direction is the object moving in?
  • Non-normalized vectors (both a direction and a scalar value)
    • How fast is the object moving and in what direction?

“Normalized” here means the length of the vector has been set to 1, making the math much simpler but removing the scalar information. (We no longer know the exact position of the original vector, only its direction.)

image12

Hot programming tip: Use a prefix for your variable names to indicate which type your value is. Here’s my quick set of conventions:

  • pos – Position
    • wPos – Position (World space)
    • lPos – Position (Local space)
  • dir – Direction
    • wDir – Direction (World space)
    • lDir – Direction (Local space)
  • v – Velocity
    • wVel – Velocity (World space)
    • lVel – Velocy (Local space)
  • acc – Acceleration
    • wAcc – Acceleration (World space)
    • lAcc – Acceleration (Local space)

The highest priority is to convey to other developers what’s inside and what its units are!

(Local space and world space are covered later in this article.)

Shooting projectiles: To look at how these vectors are used, let’s say we’re building a simple top-down video game below.

image14

We have a player (yellow) firing a missile at an enemy down below (grey). There are three things we need to know:

  • Where should the missile be?
  • Which way is it going?
  • How fast is it moving?

If we want the missile to shoot directly in front of the player, we might use a simple vector like this:

game math code 3

Or, if we want the missile to travel directly to the locked-on target, we can use the positions of the player and the enemy to find the direction:

game math code 4

Which looks like this:

image16

These examples are heavily simplified, but with just two points (starting point and desired ending point) and a speed, we can figure out exactly how to make the missile move.

Player movement: The goal here isn’t to teach you to code, but to show you how to think about these things. The math is a tool that can be used in multiple ways to serve the needs of your game.

Let’s have one more example, this time even more basic: figuring out which direction the player moves when the control stick is pushed.

game math code 5

image19

Unlike the missile example, this directional vector is not normalized. (Its size is still part of its information.

This is important because we care about how far the stick is pushed. If the stick is in the dead center (or below some low threshold), we don’t want to move:

game math code 6

If you wanted to build a platformer, you’d do the same thing, but add in acceleration due to gravity, or ask the physics engine to do so for you.

image20
(An example from Unreal blueprints of making a character move based on an input value.)

Even if you aren’t coding your game, it’s useful to understand these core concepts around vector math.

You can learn more about vector math for game developers in the video below:

Vector dot products: Finally, before we move on, I can’t emphasize how useful this next tool is, even if you don’t understand the math: the dot product.

image15
(Credit: byjus.com)

The dot product is often taught in the most confusing and annoying of ways. Instead of explaining why it’s useful, they explain how to do it and just move on. So let’s fix that.

We’ll start with the name: dot product.

The boring truth is that it’s named after the · symbol, but as far as you’re concerned as a game designer, this stands for Direction Of Travel.

If you take the dot product of two vectors, the result will tell you three things:

  • Dot product = 0: The two vectors are at a 90º angle from each other.
  • Dot product > 0: The two vectors are facing roughly the same direction (<90º angle between them)
  • Dot product < 0: The two vectors are facing roughly opposite directions (>90º angle)

The value of the dot product tells you how much they are facing away from each other. This is super useful for figuring out if something is ahead of you, to the side of you or behind you.

Trigonometry (Distance Math)

image7

In an earlier example, we wanted to fire a missile at a distant enemy. To find out exactly how far away that enemy is, we can use basic trigonometry.

image3
(Check out Pikuma.com for more examples of using math in video games.)

Because we store positions as {x,y}, we can do some simple trig (as shown above) to figure out exactly how far away we are from the target.

game math code 7

… but in practice, smarter programmers than us have pre-written these concepts into libraries, so we don’t have to memorize the formulas, just know how to use them!

You can learn more about trigonometry for game developers in the video below:

Linear Algebra

Finally, linear algebra is really just a wrapper for two terrifying concepts:

  • Formulas
  • Quaternions

Formula: Formulas describe the relationships between different values.

Let’s use the World of Warcraft spell damage formula as an example:

game math code 8

This is just basic algebra. Instead of using mysterious abstract letters like X or Y, we use actual concepts:

  • spellPower: a stat players find on their gear
  • baseDamage: a damage value designers set for each spell
  • damageCoefficient: a value designers set for each spell that determines how spell power is converted into damage
  • multi: a value calculated by the game engine from buffs and debuffs on the player and their target

That’s all that algebra is: relationships between different numbers to get useful results.

Quaternions: The nature of a quaternion is complicated. I’ll let the resources I link to at the end of this section explain what exactly they are. As a game designer, I’ll instead focus on how to use them.

If you’ve ever opened Unity, you’ve seen this:

Image11

You might have just nodded your head and said: “Yeah that’s useful”, and thought nothing more about it. Or you might have wondered, “Why are those three things there?”

image18

Well, without going into the complex math behind them, quaternions let you “transform” objects by changing their position, rotation and scale.

Transformation quaternions also let you find positions relative to an object.

Local Position =>  [Quaternion] => World Position

What’s really useful is that quaternions stack.

One calculation can position an object relative to a character, the next can place that character relative to the boat sailing by, and another can locate the boat relative to the planet it’s sitting on!

This makes it possible to track objects even if the player is running around the surface of a sphere, loading arrows into a bow, and summoning allies at the same time.

Thankfully, again, game engine programmers have made it easy for us.

game math code 9

You can learn more about quaternions from Grant Sanderon’s video series and the video below:

Floating-point Math

Before I move on, I would be doing game development an injustice if I didn’t mention the most frustrating mistake in modern technology: floating point numbers.

Now, a floating point number on its own isn’t a mistake: ever since 1997 or so, we’ve been using them constantly and enthusiastically.

The problem is that hardware programmers couldn’t agree on how to implement them, so you cannot trust that two calculations done on two different computers will have the same result.

For single player games, this really doesn’t matter too much. Who cares if you do 0.0000001 more damage than intended?

But for multiplayer games where you need to ensure both players are experiencing the game the same way, this leads to development nightmares.

Instead of simply confirming that two values on different machines are equal, you need to track how far apart they’ve become (“drift”) and reconcile them.

I strongly recommend any designer getting into multiplayer games to start with a networking engine like Photon Quantum to avoid this headache entirely.

Their tech has single-handedly made building fast multiplayer prototypes dramatically faster and fixed numerous bad architectural decisions found in Unity. (No, they aren’t paying me to say this.)

Using fixed-point math approaches like this does have side effects, but having consistent results on every computer saves an incredible amount of time in the critical prototyping stage.

You can learn more about solving consistency issues with a multiplayer project from Gaffer on Games’s post.

Discrete Logic

Finally, when creating the rules for games and explaining them to the computer, you will use tons and tons of discrete logic.

While the formal definition focuses on the hardware, discrete logic is about understanding the concepts of AND, OR and NOR.

AND:  A && B — is only true if both A and B pass

OR:  A || B — is true if either A or B pass, even if the other fails

NOR:  (!A) && (!B) — is true only if both A and B fail

Why is this important? Well, this is the art of creating conditions. Conditions are rules that Game Designers setup constantly while making game content.

image17

Game development is full of conditional checks, even when handling something as simple as opening a door.

An experienced game designer creates standard rules for how their game works, which keeps their logic clear and well-organized.

Without a careful approach, small discrete logic errors can easily break complex games.

Understanding logic and patiently thinking through an issue will often let you pinpoint the cause without diving into the game code.

You can learn more on discrete logic from

Interpolation

The next two incredibly useful mathematical concepts also come with adorable names: Lerp and Slerp.

Short for linear interpolation and spherical linear interpolation, these concepts allow you to blend between values in a smooth way.

Linear interpolation is great for quickly moving objects from point A to point B like this:

game math code 10

Combine this with a sampling curve (called AnimationCurve in Unity) and you can effortlessly move objects in a way that looks pretty natural.

It’s no replacement for the custom work of an animator, but you’ll be amazed at how far this can get you while prototyping.

image10
(Credit: Freya Holmer)

Slerp works similarly, but treats A and B as directions, instead of points, moving in an arc instead of a line. This is great for blending between rotations.

You can learn more about interpolation for game developers in the video blow:

What Math Concepts Are Important for Computer Graphics?

The previous section focused heavily on movement and gameplay, which are the areas where I usually spend most of my time.

But for those of you interested in the graphics side of game development, I’ll briefly cover a few topics that matter most in that field.

Geometry: The most important concepts in both graphics and level design are covered by basic geometry.

Levels are built up of points, lines, planes, and polygons. The basic math needed to understand these is far less important than understanding the concepts.

image8

Together, numerous points and lines form the complex polygons that create the level spaces that graphics programmers render, and that cause players to shout in triumph and tear their hair in frustration.

image2

Older games reveal the polygons more starkly than newer titles, but the underlying nature remains the same.

Vector Graphics

Not the same as vector math, vector graphics describes visuals and illustrations made with points, lines and curves, then filled in.

If you’ve ever opened an illustrator file, you know what these are about.

image5

Use these to create infinitely scalable art, fonts and more.

You can learn more about vector graphics (with example code) in the video below:

Normals

image21
(Credit: Wolfram Alpha)

The normal is an important concept in level design, describing the direction perpendicular to a surface.

image13
(Credit: Kids Can Code)

“Normal” is the weirdest possible word for this concept, but apparently “surface direction” takes too long for engineers to type. Just think of it as the direction the surface is angled.

By taking the dot product of a surface’s normal vector and the player’s up vector, you can determine if the player should be standing, sliding across, or stopping against that surface.

This makes it a fast and easy way to figure out if a player’s character should be able to walk up a cliffside or slide down.

If you ignore the vectors’ scale (pretending they’re each length 1), this is especially simple: the dot product is 1 if they are going the same direction, 0 if they are at a 90 degree angle, and 0.5 if they are at a 45 degree angle.

image4
(Credit: JavidX9)
This example involves two unrelated terms that are easily confused, so be careful:

  • A normal vector or normal is a vector perpendicular to a surface
  • A normalized vector or unit vector is a vector adjusted to length=1, keeping its direction but ignoring its scale

But the original reason for normals, and where they come up most in graphics, is their use by shaders to determine how to render the surface.

A special texture called a normal map makes surfaces seem more detailed than they actually are, improving appearance without overloading your graphics card.

image9

  1. Normal Map
  2. A high resolution model
  3. The actual model rendered
  4. What it looks like when you put the normal map on top

Local Space, World Space, and Camera Space

When I introduced quaternions, you might have thought they weren’t important for your game. You don’t plan to move objects between NPCs or let players run around the surface of spheres, so why do you need to transform between coordinate spaces?

As it turns out, quaternions are vitally important not just for translating between the local space of a character to world space, but also from world space to camera space.

image6

When you want to draw the screen, you need to figure out what color each pixel is! To do that, you need to know what the world looks like from the camera’s perspective, not the character’s.

This is important not only to shaders and rendering, but also in gameplay: when the player clicks the screen, what object is underneath the cursor?

Just like the other uses I brought up for quaternions earlier, this is usually as simple as fetching the appropriate quaternions for transforming between two systems. (In this case, you’d call on the “world to camera space quaternion” and the “camera to world space quaternion.”)

The execution here is slightly more nuanced and depends on the engine, but the important thing is that you understand their use.

Follow Up: Physics, AI, and Even More Math in Video Games

Honestly, this topic got so large, I split it into multiple articles. Math shows up in all areas of video game development, and a couple topics deserved their own space:

Physics

Physics uses just about all of the topics we’ve already covered, along with more complex coordinate systems, linear equations and lots of normal vector math to determine when objects intersect or fall.

Most games have fairly robust physics engines for both gameplay and visual effects. Knowing about joints, compound colliders and various other concepts can go a long way while working in these systems.

You can find my article on video game physics over here.

Procedural Generation and AI

These topics go beyond the math concepts themselves and into the philosophy of video game development, which is why I’m building them into their own follow-up article.

If you want to know when this article goes live, sign up for my short weekly newsletter.

Balance

My own balance work, especially in World of Warcraft and League of Legends, has taught me some important lessons on math in video game development:

  1. Math is a tool that can test human insight, but can’t replace it
  2. What works in one video game doesn’t work in another; each one needs its own approach

The same follow-up article that covers AI will also include some of my thoughts on this topic, and some behind-the-scenes peek into how WoW and LoL work.

Until then, you can get a head start with my definitive guide to video game balance.

Video Game Math Learning Resources:

Final Thoughts

A computer science student, a math student and a game designer walk into a bar.  The computer science student says “ow”, the math student says “this repeats forever” and the game designer orders a drink.

The specific skills you need are often learned on the job, on the fly, as you need them. Having a smattering of all of these will help you know the most important thing: where to start looking when you don’t know the answer.

As game designers, we live in ambiguity. We thrive in the unclear spaces where others struggle to tread.

Do not be afraid of what you do not know. Only be afraid of what you’re unwilling to admit what you don’t know.

Join the Funsmith Tavern to get exclusive game dev tips that I don’t share anywhere else

Each Friday, get a shot of 2-min TL:DR update in your inbox on the latest
Actionable tips, templates, or in-depth guides by game dev experts
— Entry-level Game design job listings(+ playtesting and internships)
— Private community workshops, events, and discussions

Leave a Reply

Your email address will not be published. Required fields are marked *

The Funsmith Tavern

Weekly Game Design Newsletter

Level-up your game design knowledge, skills, career, and network

Each Friday, get a shot of 2-min TL:DR update in your inbox on the latest

All tactics. No fluff. Pro advice only. Unsubscribe any time

Get Exclusive Game Design Tips that I Share Only with Funsmith Tavern Subscribers

Weekly Game Design Newsletter

Level-up your game design knowledge, skills, career, and network

Each Friday, get a shot of 2-min TL:DR update in your inbox on the latest

All tactics. No fluff . Pro advice only. Unsubscribe any time

EXPERIENCE & BACKGROUND:

[STUDIO] Blizzard Entertainment: Content, mechanics, and systems designer

(Creator of Apex Legends & former Creative Director at Respawn)

[GAME] World of Warcraft: MMORPG with 8.5 million average monthly players, won Gamer’s Choice Award – Fan Favorite MMORPG, VGX Award for Best PC Game, Best RPG, and Most Addictive Video Game.

  • Classic:
    • Designed Cosmos UI
    • Designed part of Raid Team for Naxxramas
  • Burning Crusade:
    • Designed the raid bosses Karazhan, Black Temple, Zul’Aman
    • Designed the Outlands content
    • Designed The Underbog including bosses:
      • Hungarfen, Ghaz’an, Swamplord Musel’ik, and The Black Stalker
    • Designed the Hellfire Ramparts final bosses Nazan & Vazruden
    • Designed the Return to Karazhan bosses: Attumen the Huntsman, Big Bad Wolf, Shades of Aran, Netherspite, Nightbane
  • Wrath of the Lich King:
    • Designed quest content, events and PvP areas of Wintergrasp
    • Designed Vehicle system
    • Designed the Death Knight talent trees
    • Designed the Lord Marrowgar raid
  • Cataclysm:
    • Designed quest content
    • Designed Deathwing Overworld encounters
    • Designed Morchok and Rhyolith raid fights
  • Mists of Pandaria: 
    • Overhauled the entire Warlock class – Best player rated version through all expansion packs
    • Designed pet battle combat engine and scripted client scene

[GAME] StarCraft 2: Playtested and provided design feedback during prototyping and development

[GAME] Diablo 3: Playtested and provided design feedback during prototyping and development

[GAME] Overwatch: Playtested and provided design feedback during prototyping and development

[GAME] Hearthstone: Playtested and provided design feedback during prototyping and development

[STUDIO] Riot Games: Systems designer, in-studio game design instructor

(Former Global Communications Lead for League of Legends)
(Former Technical Game Designer at Riot Games)

[GAME] League of Legends: Team-based strategy MOBA with 152 million average active monthly players, won The Game Award for Best Esports Game and BAFTA Best Persistent Game Award.

  • Redesigned Xerath Champion by interfacing with community
  • Reworked the support income system for season 4
  • Redesigned the Ward system
  • Assisted in development of new trinket system
  • Heavily expanded internal tools and features for design team
  • Improved UI indicators to improve clarity of allied behaviour

[OTHER GAMES] Under NDA: Developed multiple unreleased projects in R&D

Game Design Instructor: Coached and mentored associate designers on gameplay and mechanics

[STUDIO] Moon Studios: Senior game designer

(Former Lead Game Designer at Moon Studios)

[GAME] Ori & The Will of The Wisps: 2m total players (423k people finished it) with average 92.8/100 ratings by 23 top game rating sites (including Steam and Nintendo Switch).

  • Designed the weapon and Shard systems
  • Worked on combat balance
  • Designed most of the User Interface

[GAME] Unreleased RPG project

  • Designed core combat
  • High-level design content planning
  • Game systems design
  • Game design documentation
  • Gameplay systems engineering
  • Tools design
  • Photon Quantum implementation of gameplay

[VC FUNDED STARTUP] SnackPass: Social food ordering platform with 500k active users $400m+ valuation

[PROJECT] Tochi: Creative director (hybrid of game design, production and leading the product team)

  • Lead artists, engineers, and animators on the release the gamification system to incentivize long-term customers with social bonds and a shared experience through the app

[CONSULTING] Atomech: Founder / Game Design Consultant

[STUDIOS] Studio Pixanoh + 13 other indie game studios (under NDA):

  • Helped build, train and establish the design teams
  • Established unique combat niche and overall design philosophy
  • Tracked quality, consistency and feedback methods
  • Established company meeting structure and culture

Game Design Keynotes:

(Former Global Head of HR for Wargaming and Riot Games)
  • Tencent Studio
  • Wargaming
  • USC (University of Southern California)
  • RIT (Rochester Institute of Technology)
  • US AFCEA (Armed Forces Communications and Electronics Association)
  • UFIEA (University of Florida Interactive Entertainment Academy)
  • West Gaming Foundation
  • Kyoto Computer Gakuin – Kyoto, Japan