Advertisement

Why does a gameplay programmer need to know math?

Started by March 29, 2024 12:50 AM
1 comment, last by Aressera 7 months, 1 week ago

A lot of job postings for a “gameplay programmer” want strong mathematical skills. It is obvious why having more simple mathematical knowledge is important in any programming. However, specifically these postings have linear algebra, matrix and vector math as requirements often times. Why is this important to a gameplay programmer? What real uses will there be for this type of math? What are the most important concepts I should focus on/understand?

A major part of gameplay is making sure objects are at the right places at the right times. This means you must understand the mechanisms behind how objects in a scene are placed at a particular position. You need to know how to do stuff like program a door to swing open when activated, or calculate the angle an enemy should fire a projectile to hit the player. This all involves vector math. The player's position is a 3D vector, the enemy's position is a 3D vector. Rotations are where matrices come into play. It's very important you understand basic concepts of matrix math, and how it applies to computer graphics.

You should have at least a very thorough understanding of:

  • Basic matrix math. Know how to do arithmetic operations using matrices and vectors. You don't need to know how to write a QR decomposition or matrix solver. Almost all matrices and vectors in games have 4 or fewer dimensions.
  • 3D transformations using a homogeneous coordinate system, including how to do rotation, scale, translation, shear. These are usually expressed as 4x4 matrices.
  • Quaternions and rotation matrices, and their pros and cons in different situations. (Quaternions are better for interpolation and smaller, but matrices are faster)
  • Euler angles and their cons. Know how to compose Euler angles into a 3x3 matrix or quaternion.
  • Understand the cross product and dot product, their properties and what they are useful for. Cross product is for calculating perpendicular vectors, dot product is for projecting vectors onto each other.
  • Basic trigonometry: understand sine/cosine/tangent and how they relate to rotations. Know how to calculate an angle given slope dY/dX.
  • Undergrad-level physics (classical mechanics) with calculus. You need to understand how to integrate acceleration to get velocity and velocity to get position. You should understand what a derivative is, and how to calculate finite differences (e.g. to estimate an object's velocity given current and previous positions). You should be able to program a spring oscillator that moves up and down in a sinusoidal way as you integrate the forces forward in time.
  • Computational geometry - understand basics of how geometry is handled in games: bounding volumes, triangle meshes, convex hulls, ray tracing intersection tests, etc. You should be able to write a function to determine if two spheres or axis-aligned bounding boxes intersect. You don't need to know how to write a physics engine collision detection system.

This topic is closed to new replies.

Advertisement