# Math is for Game Development!

**Posted by** Rampant Coyote on September 7, 2012

Okay, this one’s for the kids.

Wanna make videogames? Learn to love math! I’m not sure if videogames or sending space ships to other planets represent the culmination of all that great work by the mathematicians and scientists of the past like Euclid, Archimedes, Newton, Decartes, Acharya, and Fibonacci. But it ranks pretty highly up there in my biased opinion. Game development is all about math, but the math is actually pretty fun. Math in videogames is what makes explosions work, what makes the AI move around cover to find you, what makes that lobbed grenade hit its target, what makes the physics puzzles work. Okay, yeah, sometimes the thrills it gives are pretty geeky, but I come from an era where these games were pretty geeky to begin with, so it appeals to me. 🙂

I think my game-development habit in my younger years was what helped me get through my math classes. While the rest of the class got glassy-eyed learning trigonometry, not really sure what possible value sines and cosines would have in real life, I was eating that stuff up, because I saw how they solved problems in game development. In some cases, I’d already learned some of it on my own. So I guess, in a sense, my passion for making videogames actually made math kinda fun – which is quite an accomplishment on its own, and I think in turn that made some things a lot easier to learn.

Algebra and trigonometry are things I use almost every day. I was reminded of this the other night when I found myself writing code for slope-intersects… another one of those things taught in math class that few of my fellow students really could see a practical application for. I survived a semester of Statistics my final year in college mainly because the first quarter of the class was all about probabilities – something I’d internalized pretty well spending years playing Dungeons & Dragons.While the deeper secrets of samples and distribution were a lot more challenging for me, anybody who is working in the MMO field and has to deal with large populations of players could benefit from this kind of knowledge.

I use Calculus a lot less in my work in games (and simulation, my day job) – but the foundation it provided was helpful. The physics classes I took in college – which required Calculus – were probably even more useful.

Want to program? Programming *is* math, guys. On its most basic level, programming is all about transforming meaning into numbers and vice versa – everything in a computer is a number, and every instruction is, at a fundamental level, a mathematical operation. Even at the higher level at which we programmers generally operate nowadays, programming is the embodiment of those “word problems” the kids complain about in school.

There have been times – especially when I was younger and really learning all this stuff – when I DREAM in code. I remember one windy night when I couldn’t sleep, and my brain got stuck in this loop describing the swaying of trees in the wind in terms of mathematical equations. Years later, working with Curtis (Califer on the board here) on the archer rats on the **Tale of Desperaux** video game, when we researched the algorithm for artillery trajectories to implement in the AI code to make the archery AI more accurate and give their arrows a more realistic “lob” effect. Programmers are always solving for X, performing summations, and otherwise performing basic arithmetic and algebra. If you are working in 2D or 3D space – as you are when writing many videogames – knowing where to perform an arctan (and its limitations) or calculating the distance between two points ( sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1)), for 2D space – it’s second nature ) are frequent problems. Particularly in 3D code (AI, graphics, or physics), you’ll find frequent uses for things like dot products, cross products, matrix math (hoo, yeah!), calculating intersections between planes / lines, and the like.

Designers? Oh, heck yeah. As a designer your math background may not need to be quite as extensive as a programmer’s, but designing videogame mechanics is really an exercise in math. Remember how I said I thought probability calculation was pretty intuitive in my Stats class because of Dungeons & Dragons? That’s what I’m talking about. Mechanics design is all about understanding and manipulating the mathematical relationships between game elements. Good designers know a bit about an awful lot of topics – drawing from all art, science, literature, history, current events, or whatever – but they also need a solid math foundation.

And yes, math plays a role even for the artists. In some companies where I’ve worked, we’ve had a Technical Art Lead whose job it was to help keep the artists meeting the technical specifications, but an artist who understood the technical (math-based) environment for which he or she was creating assets was oftem more productive by the simple fact that they didn’t need to re-do so much work.

So – if you are a student, or know a student who is interested in video games… let this serve as a reminder about the importance of math.

**Filed Under:**Geek Life -

**Comments:**11 Comments to Read

Noumenonsaid,This Ratchet and Clank developer commentary makes it clear how important matrix math and vectors can be when trying to code something like a spherical moon level.

Califersaid,I remember that! It was fun filling that poor little mouse full of arrows 🙂

Maklaksaid,Hehe. One of my exercises for STL was modifying code that moved dots on the screen.

First problem was that collisions with the borders were handled by flipping speeds and not drawing dots when they were outside the screen. I thought I’d have to consider several special cases, especially “double collisions” around the corners. The solution turned out to be simple and elegant. If a coordinate after movement was outside the border, I flipped the speed and mirrored the coordinate by that border. That is x = max_x – (x – max_x). Same for x too small, y too big and y too small. It also solved all those corner cases.

Then I wanted the dots to collide with themselves, but gave up on the proper solution and did a dirty hack instead: If two dots are inside the same pixel and they haven’t recently collided with each other, collide them using equations for elastic collision for wikipedia.

It worked, but not the first time (including a nasty case of subtracting unsigned masses and getting an overflow) and taught me some proper respect for even “trivial” problems.

Corwinsaid,As someone who taught high school math for many years, thanks for the plug. My Math classes were always FUN!! 🙂

WhineAboutGamessaid,@corwin Are modern math classes allowed to actually admit the usefulness of technology yet?

I didn’t *hate* math in school and was reasonably good at it, but I hated doing pages and pages and pages of repetitive work to test my ability to not die of boredom, being asked to memorise complicated stuff that is better handled by keeping a reference handy, and being asked to solve things the long way rather than relying on the tools humanity has built to speed this stuff up.

Programming is a great way to solve most math problems, if they’ll LET you…

(On the other hand, I loved word problems! Everyone else hated them.)

Felixsaid,Story of my life, really. Spent most of school hating math with a passion, until the last year of high-school when we

finallygot a teacher who could be bothered to explain what math is good for. And then I started making games, and it was so fun learning math and physics on my own.That’s what all school should do: teach kids what learning is

for. The learning proper they can do themselves just fine.Charlessaid,This just doesn’t add up. Then again, maybe I’m a bit rusty 🙂

Noah Donnellysaid,Speaking from a student’s point of view, I can say that since I started programminhg, I’ve started to work harder in my maths classes, and enjoy them so much more. I can now understand, at least a little bit, why my teacher says she loves maths. I’m constantly confused as to why programming isn’t part of the curriculum, even in IT classes.

McTeddysaid,Just in case anyone reading here sucks at math… don’t worry!

I’ve struggled through every math course I’ve ever taken. I was constantly reminded as a child that I would never be able to make video games because I almost failed Algebra. Words like “Computer programming is all math” scare the **** of me to this day.

But here I am, a shipped video game developer whose done everything from physics engines to Artificial intelligence. I do use math everyday, but it’s different.

I use mathematical logic and processes far more than actual math. It’s far more important that you understand why we use the math and how it works than being able to solve the equation yourself.

Sure… everything would be easier if I had some math talents, but if I can program ANYONE can.

Don’t let this math stuff scare you away!

Albert1said,Programming is math… I agree. The problem, in my opinion, is that while the best programmers are very good at applying math, very few of them really have a true mathematical mindset! The divorce of CS from math caused lot of damage: what most programmers mean when speaking of abstraction – the Holy Grail in our field – has very little to do with the abstraction math succesfully delivered, for centuries, to hard&soft sciences. Game and simulation developers are very proud of modeling “real” worlds, yet they take the opposite direction than, say, an engineer. As far as I know, in every field systems are modeled breaking ’em down to known mathematical relations, then, and only then, if the phenomena observed are truly new, new concepts come in to play. In short: what OOP purists call abstraction is quite the opposite: going from abstract to a multitude of special cases. Even component-based entities are, in my humble opinion, unsatisfying. I think that, to support mathematical abstraction, a language should have the following features:

– extensive array programming

– builtin linear system, matrices, etc.

– goal-directed evaluation a la Icon

– pattern matching

It’s quite difficult for the aforementioned features to make their way in C++, just to name a popular language in game development.

Yoelsaid,I hated word problems. I could never figure out what was what or what to do with it. They would infuriate me and threaten, over the course of far longer than I was intended to spend on them, to drive me to tears.

I love programming.

What the heck is wrong with me?