How Math Is Used to Build Video Games
Written by Stuart Denman
Step into the captivating world where mathematics and gaming intertwine! While I am a Board Member of Seattle Universal Math Museum (SUMM), my full time job is making video games.
Game development isn't just about puzzles and art – it's a symphony of numbers, formulas, and equations that bring virtual worlds to life. In fact, video games would not exist without math. To imagine this, let’s come up with a new game idea!
Follow me and enter the enchanting realm of "Wonders of Summeria" and I will unveil the mathematical secrets behind its creation.
How Math Creates Vibrant Game Colors
The vibrant landscapes in Summaria burst with color, captivating players at every turn. But how do developers achieve such mesmerizing visuals? Enter the RGB (red, green and blue) color model, a mathematical marvel that serves as the cornerstone of digital content everywhere: from Tiktok videos to video games. By combining different intensities of red, green, and blue light, we can create a dazzling array of hues. To understand just how many colors I mean, let’s break down how this works: colors are conceived using 3 numbers, called a color’s components:
Final Color=(red, green, blue)
Each component ranges from 0 to 255, with 0 representing no intensity (no light) and 255 representing maximum intensity. Why 255? Because that’s the largest number you can store in one byte of a computer’s memory. Let’s just say that it makes saving and storing millions of these color values a whole lot easier. One byte is 2⁸ (or 8) bits. For those of you that already know some math and a little about computers, that’s 256 possibilities for each component and to store one color takes 3 bytes.
If you combine red and green light, you get yellow. Useful for the walls of the town’s buildings. Blue and red light makes magenta, which is very close to pink. We can use magenta to enhance our player’s costume. By mixing less or more of each component, you can make 2²⁴ (that’s 2 multiplied by itself 24 times) or nearly 17 million different colors and shades!
The Math of Animating Characters and Objects in Games
As you explore Summeria, you’ll encounter friendly woodland creatures like fluttering butterflies and playful foxes. But how do they move so smoothly across the screen? That's where math steps in again! Developers use algorithms (mathematical rules and formulas) to calculate the trajectory, speed, and acceleration of objects, making their movements look natural and lifelike.
Animators use formulas to speed up and slow down creatures when they animate. These are called easing functions. One of the most commonly used easing functions uses squaring, where you multiply a number by itself. In animations, that number will be based on the time that has passed since the animation started:
By adjusting parameters such as the distance to travel, the starting position and time duration, developers can tailor the motion of objects to suit the needs of the game design and art direction. The same formulas can even be used to animate colors over time. Imagine a sunset that slowly blends over time from bright blue to purple, to coral, and finally a deep orange.
Balancing Game Difficulty with Math Models
Every level in the game presents a unique challenge, carefully crafted to test the players’ skills. Let’s say we want to create new items to buy in our town square marketplace. How much power should a magic wand have and how much should it cost? Well that depends on how long the player has been playing the game and how good they are at playing. As the player improves in ability, the game needs to progress along with them. This is known as game progression.
Behind the scenes, developers rely on math to ensure that the gameplay experience remains engaging and balanced. If the game is too hard, players might rage quit! One such mathematical model is the exponential growth curve, which governs the progression of difficulty throughout the game:
Developers can fine-tune the curve to achieve the perfect balance between challenge and reward. This formula can be used to answer many questions, for example:
How powerful should that tornado be at the end of the sand world?
What kind and level of spells to offer the player in the shops?
How much should things like our magic wand cost?
How often should the player encounter new events in the game?
Enhancing Video Game Design with Data Analysis and Math
Once Wonders of Summeria is released into the hands of eager players, the adventure is just beginning – not only for gamers but also for the developers. Enter the Game Data Analyst, a mathematical maestro who sifts through oceans of player data to uncover valuable insights that shape the future of the game.
Their job is to embark on a quest to understand how players interact with the game. To do this, analysts use a math called statistics, which takes millions of numbers and combines them in a way that can be understood by humans. Is it magic or math? Math of course! One very common formula is called the average which is a way of saying “which number is the most common”:
In this formula you can see many numbers called “n” but here we only have 5. Even with millions of numbers, the formula looks very similar (add them up then divide by the quantity of numbers). These numbers are measured by the game’s code and represent things like how many times a player uses a health potion in a certain level or how many attempts a player took to solve a puzzle. The average formula then tells us what is most typical for players and this is what we call a metric.
Suppose the analyst notices a sudden drop in player activity around a particular level of the game. Metrics such as completion rates, time spent on the level, and frequency of retries, can identify potential bottlenecks or frustration points that may be deterring players from progressing further. Armed with this knowledge, developers can rework level designs, adjust enemy difficulty, or provide additional hints to smooth out the player's journey.
Here’s another example: the analyst discovers that a freeze potion is rarely used by players, despite being scattered everywhere in the forests of Summaria. With this insight, developers can reevaluate the potion's usefulness, redesign its functionality, or introduce new incentives to encourage its usage. Maybe we add more fire rats, which are particularly vulnerable to freeze potions.
In this way, math becomes a powerful tool for continuously refining and enhancing the game content based on real-world player behavior. Guessing about this kind of thing is often wrong and can waste a team’s time and money.
In Conclusion: The Impact of Math on Video Game Innovation
Perhaps now the mysterious world of Summeria is just a bit less mysterious, but we've only just scratched the surface of how math fuels the magic of video game development. From crafting captivating visuals to orchestrating thrilling gameplay or illuminating the darkest corners of player behavior, math is the unsung hero behind every pixel and polygon.
So, the next time you pick up your controller or embark on a virtual quest, take a moment to appreciate the incredible role that math plays in bringing these digital worlds to life. Who knows? Maybe you'll discover a new appreciation for the power of numbers and find inspiration to start your own game making adventure!
Seattle Universal Math Museum’s mission is to spotlight the fun and useful side of math! Please donate and subscribe to our newsletter to support more great content like this.
To learn more about Stu and his games, visit pinestreetcodeworks.com