How is math used in video game designing and programming?

How is math used in video game designing and programming? by @MattStenquist

Answer by Matthew S. Stenquist:

Math is an absolute fundamental foundation to successful game development and game design.

Math is everything when it comes to games. From having the ability to calculating the trajectory of an Angry Bird flying through the sky, to ensuring that a character can jump and come back down to the ground — without the help of mathematics, games simply wouldn't work.

A character wouldn't be able to walk up a slope, slide down a slide, fire a bullet from a gun, or even jump without the help of the mathematics.

The most basic of games use some form of math to the most complex of games.

Math is essential to the production of games. It is the flour to the cake that game developers are trying to bake. Without it, the cake wouldn't rise.

Math is used in every aspect of game development, including art. Maya is a math based program that plots out the vertices and normals in mathematical form while the artist just uses a tool that allows them to create stunning 3d graphics without worrying about math. Simply put, you could model Godzilla in notepad and pushing it into Maya, if you knew were to plot the points in numerical form (which is extremely difficult).

However, a lot of the math is computed at runtime and handled by the game engines that render back face culling, and the other nitty gritty things that would be too cumbersome to do without the use of using an engine to alleviate the math calculation portion at runtime.

A lot of math in gameplay scripting is fairly simple, but math used in game engine architecture is far more complex and a lot more taxing mentally. Math in game development is simulated either by the developer or handled by the engine at runtime by running computations to calculate the operation that is needed.

Here are some examples.

  • Ocean waves crashing nicely against your boat in ASC: Black Flag? Math.
  • Those bullets flying over your head in Call of Duty: Ghosts? Math.
  • That fancy UI animation that's procedurally generated? Math.
  • Sonic being able to run fast and Mario being able to jump? Math.
  • Drifting around that corner in Need for Speed at 80mph? Math.
  • Snowboarding down a slope in SSX? Math.
  • That rocket blasting off in Kerbal Space Program? Math.

Here's an expanded example using Mario's jumping mechanic.

  • When Mario jumps he isn't just going straight up and down on the Y-Axis but rather creating a parabola to jump up and down. It would be quite silly for Mario to beam up and then beam across on the X axis and then straight down on the Y-axis. Certainly, it would look goofy and not quite right.

Another example for instance is, Kerbal Space Program; a game that relies heavily on math. The entire game is pretty much all math when you think about it.

Newtonian physics are heavily simulated in KSP. Without the use of math in KSP, the game wouldn't be able to do much. Your rocket wouldn't be able to get off the ground and out of the atmosphere into space. The simulations in the game would be boring, and quite frankly the game wouldn't be able to do much. A rocket wouldn't be able to get off the ground because thrust doesn't exist, and or be able to pitch,yaw,and roll when in the sky.

In game development we're allowed to get away with faking math so that it is to work with the design of a game, but a lot of the time the math in games mirror real world physics and math principles. Math helps out with calculating everything from what a particles velocity should be, to the spread of a shotgun blast, to using gravity to bring a ball back down to the ground, and vice versa. These are all very basic math principles that a lot of games use. And their is still much more sophisticated and advanced math used in AAA games that I haven't covered.

What are the main branches of math used in game development?

  • Algebra
  • Discrete Mathematics
  • Trigonometry
  • Calculus
  • Linear Algebra
  • Applied mathematics
  • And much much more….

Some of the most important math used in games.

  • Dot Product, Cross Product.
  • Scaling Vectors, Unit Vectors, and Vectors.
  • Reflection, Matrices.
  • Scalar Manipulation.
  • COS,SIN,TAN.
  • Delta Time.
  • Domain and Range.

Most of these math topics are all used all together in very advanced games. But, in simpler games the math may only require trig and algebra, to a handful of math using only scalar multiplication.

How is math used in game programming and game scripting?

Math in game programming can be as easy as adding x + y, to calculating and manipulating cos, sin, tan with added variables while stringing it to your function, all the while their is still much much more advanced ways to use math in games.

Let's take a look at creating a constant variable called MAX_SPEED and MIN_SPEED (vectors) and adding that to the game update loop while adding a speed to a spaceship so that it can move, to creating an array that runs an algorithm that loads a random level every time the game is played, to simply altering a child's X (vectors) in the update loop, or to adjusting the angle of rotation once it hits a wall (reflection) on a spin wheel when a ball hits it. Doing any sort of basic thing, such as movement in a game will incorporate some form of math.

Math is essential ingredient that is necessary to the production of games. Without the use of math in games we would just have pretty art that's semi-interactive. Math adds a whole new element to entertainment by blending the sciences and arts into a whole.

With that being said, mathematics allows games to do incredible things that the real world cannot simulate by allowing new ways for the game script and engine to handle calculations on the fly that would not be feasible to do in the real world. So next time when you question your math teacher if you're going to ever use "Algebra" in the real world when you're done with your studies, you sure will especially if you pursue a career in game development.

What can math do in game design?

  • Fluid water simulation.
  • Animation.
  • Algorithms.
  • Game engine architecture.
  • Gameplay scripting. (walking, shooting, jumping)
  • Analytics and data mining. (analyzing players interaction)
  • Timers programming (delta time, etc).
  • Physics programming (inertia, friction, etc).
  • Graphics/Shaders programming (matrices,etc).
  • Path finding/AI.
  • Procedural level design.
  • Handling Polygon rendering.
  • And much much more.

The things listed above are only but a fraction of what math is able to help out with in game development and game design.

Here are some books I recommend reading.

How is math used in video game designing and programming?