# Mathematics in game making

65 replies to this topic

### #1 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 05:51 AM

Lately, I have been wondering how important mathematics really is in programming games. I'm not talking about basic math like addition and square roots, but rather things that would not be taught until high school or college.

When I think about mathematics in game making, the first thing that comes to mind is trigonometric functions. I use them a lot for motion, distance calculation and wave-like effects. However, I only need the basics - I have for example never needed to know that sin(A + = sin(A) cos( + cos(A) sin(. I can't even remember any time I needed to use tan(x)...

Another thing I've used occasionally is probability, but always on just a very basic level.

Most of the time, it seems as the things you really need, are algorithms that don't require a sophisticated understanding of mathematics, but rather just thinking the right way. Now, I know that mathematics is really broad, but for the sake of this discussion, let's think of maths as separated from algorithmic thinking. For example, you normally don't need maths to implement a fairly sophisticated sorting algorithm, but having an efficient algorithm isn't even that important all the time, since you very rarely need to sort thousands of items in a game.

Another example is pathfinding and graph theory. This is another example that often comes to mind when I hear mathematics in game making, but when I think about it, it only requires very basic knowledge of graph theory. If you know how the A* algorithm works, then that's all you need - and maybe even the simplified Dijkstra's algorithm is sufficient for most purposes.

It seems as although having a very good understanding of basic mathematics is often very helpful, you don't need advanced maths very often. Not to say that being good at maths is wasted - I'm sure at some point we will all encounter a problem that requires some special maths, but these don't happen often.

So what do you think; to what degree is advanced mathematics needed to make games?

Edited by Marius, 12 July 2011 - 05:52 AM.

• 0

### #2 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• Retired Staff
• 9314 posts
• Version:Unknown

Posted 12 July 2011 - 06:00 AM

You don't need any mathematics at all to make a game. But it's not about requirement, it's about supplement. Understanding mathematics allows you to create better games.

And you say you've never needed to use the tangent function? I guarantee you you have, you just don't know it. point_direction() is a wrapper for atan2, which is a variation on the arctangent. And inverse trig functions don't make much sense without their basic counterparts. Of course, tan(x) is really just sin(x)/cos(x) anyway, so if you've ever divided a sine by a cosine, you've used tangent even if you gave it a different name.

Mathematics in game making, if you assume all the geometric functions are wrapped by the language you're using, is mostly useful in optimization. For example, if your online game needs to download a minor update, you could download the entire new file...which would be slow. Or you can use math to compress it.

Math isn't there "because everyone uses advanced mathematics all the time". It's there because if you know it, you can create new things that you can't without understanding it. It drives technological progress and models the world, and without "advanced" math like inverse logarithms raised to imaginary powers (e^ix), even something as simple as a pendulum wouldn't be well-understood, only estimated.

-IMP
• 5

### #3 tangibleLime

tangibleLime

Lunatic

• Global Moderators
• 2520 posts
• Version:GM:HTML5

Posted 12 July 2011 - 06:01 AM

Concepts in college-level math can be crucial to game development. Game physics comes to mind first. Then there are things such as optics, Markov chains and all sorts of neat concepts. The thing is, most of these are usually built into the game engine, which is why you don't need to know, for example, linear algebra to use a Markov chain implementation. Another example: try creating a 3D-game without using GameMaker's built in 3D functions, which do all the math for you.

In conclusion, yes. High-level math is very important to game making.

EDIT: You also may be forgetting the computer-science-ized math classes that allow you to create better, more efficient algorithms, so your end-users don't sit at their computers for 20 minutes while an array sorts. Example being using Bogosort with O(inf) versus using Mergesort with O(n log n).
• 2

### #4 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4195 posts
• Version:GM:Studio

Posted 12 July 2011 - 06:10 AM

For games that are number-heavy (such as Role-playing games, MOBAs, etc), having a good idea on how the stats interact with each other is crucial to creating a balanced game. For example, a typical method of computing damage reduction multiplier from armor is to use the following formula: 100 / (100 + Armor). Although the formula for this is non-linear, the effective health is. Meaning that for every 1 point of armor your will have, it will be like their health has increased by exactly one percent. This relationship may not be obvious.

A more naive way of doing armor is to simply subtract that number of points from the damage. This typically results in an unstable combat system where either stacking damage or armor would be way to beneficial, as you'll either one-shot the enemy or be impossible to destroy.

As for advanced maths, I would say that you really don't need any of it. (For me, advanced math is anything relating to graduate level mathematics. Anything in undergraduate mathematics typically will be useful in game development in one way or another.)
• 1

### #5 tangibleLime

tangibleLime

Lunatic

• Global Moderators
• 2520 posts
• Version:GM:HTML5

Posted 12 July 2011 - 06:17 AM

As for advanced maths, I would say that you really don't need any of it.

You fail to realize that most all games require symplectic topology.
• 1

### #6 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 06:22 AM

@IMP: I don't consider using arctangent the same as using tangent. I have used atan2 very much, but I have very rarely used atan just on its own. I don't think I've used a sin/cos either (though I might have), but if I did, I probably would have written tan instead.

@tangibleLime: Game physics is of course a good example, and if you want to make an advanced physics engine from scratch, you would of course need some theory to support you, but for almost all purposes, I don't think you need to know anything advanced (like using imaginary numbers to represent periodic functions), or you could survive with approximations. The same goes for 3D - I don't expect people to make their own engine.
What I'm saying is not that mathematics is not important to games. I'm not saying that people shouldn't care about maths either - understanding it would definitely help. My point is that it often seems as being very good at maths won't help you THAT much as a game developer, as long as you have a good understanding of the fundamentals.
Btw, as I mentioned, I don't consider sorting algorithms to require much math. Implementing mergesort isn't that hard. If you want, you could say that quicksort requires some work to find the best partition element, but other than that, it's mostly just algorithms. In addition, when I've been sorting things in games, I rarely sort very many elements, which means most of the time, O(n^2) algorithms like bubblesort will work.
• 0

### #7 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• Retired Staff
• 9314 posts
• Version:Unknown

Posted 12 July 2011 - 06:29 AM

@IMP: I don't consider using arctangent the same as using tangent. I have used atan2 very much, but I have very rarely used atan just on its own.

I'll create a custom banner for you saying "I PWNED IMP" if you can define "arctangent" without using or defining "tangent". (Note to those math-heads here who will no doubt find an obscure answer: I'm only asking Marius And Taylor expansions don't count, either!).

@tangibleLime: Game physics is of course a good example, and if you want to make an advanced physics engine from scratch, you would of course need some theory to support you, but for almost all purposes, I don't think you need to know anything advanced (like using imaginary numbers to represent periodic functions), or you could survive with approximations. The same goes for 3D - I don't expect people to make their own engine.
What I'm saying is not that mathematics is not important to games. I'm not saying that people shouldn't care about maths either - understanding it would definitely help. My point is that it often seems as being very good at maths won't help you THAT much as a game developer, as long as you have a good understanding of the fundamentals.
Btw, as I mentioned, I don't consider sorting algorithms to require much math. Implementing mergesort isn't that hard. If you want, you could say that quicksort requires some work to find the best partition element, but other than that, it's mostly just algorithms. In addition, when I've been sorting things in games, I rarely sort very many elements, which means most of the time, O(n^2) algorithms like bubblesort will work.

So...you're saying "game developers don't need to worry about advanced math because other game developers will worry about it for them"? I suppose that's true of anyone in any profession. "Surgeons don't need to worry about medicine because their assistants can worry about it for them." While true, it's a poor outlook on life.

-IMP
• 0

### #8 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 06:31 AM

As for advanced maths, I would say that you really don't need any of it.

You fail to realize that most all games require symplectic topology.

I lol'ed, then I felt really nerdy for lol'ing

@xshortguy: Those are interesting arguments. The formula for damage reduction is not very advanced, but I think it would require a very good understanding of maths to be able to figure out by yourself that it's a good formula to use, or even to understand that there is a weakness in subtracting the armor directly.
I'd say such things come with expereience though, and not necessarily education. If that's the case, then it seems as a waste of time to get postgraduate education. Maybe undergraduates should just get straight into game development without further education?
• 0

### #9 tangibleLime

tangibleLime

Lunatic

• Global Moderators
• 2520 posts
• Version:GM:HTML5

Posted 12 July 2011 - 06:33 AM

Btw, as I mentioned, I don't consider sorting algorithms to require much math. Implementing mergesort isn't that hard. If you want, you could say that quicksort requires some work to find the best partition element, but other than that, it's mostly just algorithms. In addition, when I've been sorting things in games, I rarely sort very many elements, which means most of the time, O(n^2) algorithms like bubblesort will work.

I was using that as a simple example instead of hashing out some complex algorithm that does some crazy thing. Obviously sorting algorithms require very little math.
• 0

### #10 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 06:36 AM

@IMP: I'm not saying tangent is overall useless, just that I hardly use it at all. Even though atan2 builds on atan which again builds on tan, atan2 seems to be a much more useful function than both tan and atan in terms of... well, usefulness. Like, if you need a hammer, then the hammer is useful - a piece of wood and some iron is not (heh, maybe a stupid analogy...).

Edit: @tangibleLime: yeah, but I haven't needed many complex algorithms that does some crazy things...

Edited by Marius, 12 July 2011 - 06:38 AM.

• 0

### #11 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4195 posts
• Version:GM:Studio

Posted 12 July 2011 - 06:38 AM

It doesn't take an advanced understanding of mathematics to understand that formula; in fact such things aren't taught in mathematics classes. Those things come from applying the mathematics that is learned in the class. No one is ever taught mathematics, they are simply introduced or nudged to it. Mathematics is something that individuals must come to realize on their own. There's often little nuggets of information that isn't always realized by even professional mathematicians.

Here's an interesting story related to this: http://www.snopes.co.../unsolvable.asp
• 2

### #12 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• Retired Staff
• 9314 posts
• Version:Unknown

Posted 12 July 2011 - 06:52 AM

Here's an interesting story related to this: http://www.snopes.co.../unsolvable.asp

Wow. That's awesome . I think every professor should assign unsolved problems in their field to their students as homework--without telling them they're unsolved. Just tell them they're a bit harder than usual, but that the students can handle it given some extra time. Set them loose, and when the due date comes, let everyone know the truth and see if anyone's solved them .

-IMP
• 0

### #13 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 06:56 AM

Here's an interesting story related to this: http://www.snopes.co.../unsolvable.asp

Wow, if I had done something like that, my life would feel complete and I could die happy

By the way, if anyone has ever had a problem where they got limited by mathematics, I would love to hear about it.
• 0

### #14 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• Retired Staff
• 9314 posts
• Version:Unknown

Posted 12 July 2011 - 07:08 AM

Here's an interesting story related to this: http://www.snopes.co.../unsolvable.asp

Wow, if I had done something like that, my life would feel complete and I could die happy

By the way, if anyone has ever had a problem where they got limited by mathematics, I would love to hear about it.

Define "limited". In most cases, if I can't think of how to do something, I can find a script someone else has made for it. But I feel much more accomplished when I can figure it out on my own instead of relying on other people to do the work for me.

Case in point: FlyBox and Blastix. They're two games I made (both of which were abandoned just before they were ready to be released, unfortunately) based on moving colored blocks around to try to form groups of 3 or more of the same color. The hard part was determining these groups when the blocks could be 3 or MORE to a group, in any shape, possibly with other-colored blocks around them. I didn't know how to do it, but luckily Sinaz helped me out with a floodfill script.

If I hadn't gotten lucky enough to have Sinaz help, I'd never have been able to get that game working, since to this day his is the only ds_grid floodfill script I've ever seen for GM. And that script had some serious math in it (at least, I think; the variable names were so non-descriptive I really didn't know what was going on ) .

-IMP

Edited by IceMetalPunk, 12 July 2011 - 07:09 AM.

• 0

### #15 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4195 posts
• Version:GM:Studio

Posted 12 July 2011 - 07:19 AM

Define "limited"

First, I'll define a cluster point c of a set A. Then I'll define "limited"

A cluster point c of a set A is a point such that $V_\varepsilon \left( c \right) \setminus \{c\} \cap A \neq \varnothing$ for all $\varepsilon > 0$

For a given function $f : A \rightarrow \mathbb{R}, f$ is said to have a limit L at a cluster point c for every $\varepsilon > 0$, there exists a $\delta$ such that if $x \in V_\delta \left( c \right)$ then $f(x) \in V_\varepsilon \left( L \right)$.

Something is limited if the above limit exists.
• 0

### #16 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 07:28 AM

No, xshortguy, not that kind of limited -.-'

More like you get a problem that you couldn't solve without using some "advanced" mathematical theory. Yes, I know "advanced" is very subjective, but you're intelligent, so I hope you can understand what I'm looking for even if I'm not very formally correct

I'm going to make a seminar about informatics and applied mathematics, and I have no idea how advanced I should make it, so I was thinking something related to games is a very safe bet. For this reason, it would be great to have very tangible examples.
• 0

### #17 xshortguy

xshortguy

GMC Member

• Global Moderators
• 4195 posts
• Version:GM:Studio

Posted 12 July 2011 - 07:37 AM

There's guides out there explaining how the mechanics of various games work that users have figured out. The one that sticks out in my head is the Battle Mechanics guide for Final Fantasy Tactics, over at www.gamefaqs.com.

As for the mathematics that's extremely useful to know as a game developer [disclosure: I am not a professional game developer], I'd say that linear algebra, rotations with quaternions, and three-dimensional geometry is the most important in terms of designing a game world. Other things that are important are discrete calculus (unless you have a computer that isn't digital, although regular calculus is very similar to discrete calculus), graphs, and knowledge of elementary functions (exponential, trigonometric, hyperbolic, logarithms, polynomials, etc.).
• 0

### #18 Marius

Marius

GMC Member

• GMC Member
• 204 posts

Posted 12 July 2011 - 08:38 AM

Those are some good suggestions, I'll look into it. But again, some of those things are stuff you don't really need that often. You could maybe defend it by saying that these things are details you strictly don't need, but when you start getting good at something, you have to work with the details to improve further.
• 0

### #19 IceMetalPunk

IceMetalPunk

InfiniteIMPerfection

• Retired Staff
• 9314 posts
• Version:Unknown

Posted 12 July 2011 - 09:19 AM

Those are some good suggestions, I'll look into it. But again, some of those things are stuff you don't really need that often. You could maybe defend it by saying that these things are details you strictly don't need, but when you start getting good at something, you have to work with the details to improve further.

Well, there's another relative term: "need". You don't NEED to know that 4*4=16 if you know that 4+4+4+4=16, but it helps. So what exactly are you using for your metric to measure if something is "needed"? If you say "can't make a game without it", then really, as long as you know only addition, you can make a game in GM with no further mathematical knowledge. It'll be a crappy game, but a game nonetheless.

So what kinds of systems or engines define your limit for "need"?

-IMP

Edited by IceMetalPunk, 12 July 2011 - 09:20 AM.

• 0

### #20 TheSnidr

TheSnidr

That guy

• Global Moderators
• 2471 posts
• Version:GM:Studio

Posted 12 July 2011 - 09:49 AM

I don't know what you mean by advanced mathematics (everything beyond multiplication?), but you don't lose anything from knowing more math.
Knowing math generally makes you more free when it comes to game design. I've recently found great use of the vector math I learned at school, for example. You wouldn't be able to create this without experience with vector operations.

Vectors and quaternions are probably the most "advanced" mathematics I know though. To some they may seem really hard, to others they may seem basic. Advanced math is relative

Edited by TheSnidr, 12 July 2011 - 09:53 AM.

• 0

#### 0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users