Game Mathematics
Game mathematics is the vector, trigonometry, matrix, and geometry math that game engines use to position, rotate, move, and collide objects on screen. It is the calculation layer under features like character movement, camera control, aiming, and physics response, expressed through engine types such as vectors, transforms, and quaternions.
itSoftware engineering | OpenSkills.info
Recommended first:game-engine-fundamentals
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic: Game Mathematics
Game mathematics is the calculation layer beneath movement, turning,
cameras, and collision. It is not a separate engine hiding under the engine.
It is the small set of operations that the engine's friendly names eventually
ask for anyway. A Vector3 may look reassuringly like a container with a
job title, but it still expects you to know whether its numbers describe a
position, a direction, or a velocity. Numbers are loyal, but they do not
volunteer context.
Coordinate spaces explain why an object can be perfectly correct in local space and spectacularly misplaced in world space. A transform carries position, rotation, and scale so an object's own geometry can join the shared scene. The important part is the order: combining a parent and child transform in the wrong order can rotate around the wrong point while producing results that look mathematical enough to be believed. Check the engine's convention before arguing with the matrix. The matrix has already had a difficult day.
Vectors are the daily workhorses. Subtract one position from another to get a direction. Normalize it when only direction matters. Use a dot product to ask whether two directions agree, or a cross product to build a perpendicular normal. Movement is position plus velocity times elapsed time, which lets the same speed survive different frame rates. The surprise is that a zero-length direction is not a disappointing vector. It is a state that needs a decision before any normalization happens.
Quaternions handle rotation when Euler angles become awkward. Euler angles are readable, but two axes can align and remove a degree of freedom. A quaternion avoids that trap and supports smooth rotation interpolation. Use lerp for positions and scalar values. Use slerp for rotations. Treating a quaternion as four unrelated values is how a smooth turn becomes a small geometric protest.
Bounding volumes make collision checks affordable by asking a cheap question first. An AABB or sphere overlap says two objects might touch, not that the final shapes do. The usual sequence is broad approximation, then a more precise check when needed. The same habit applies across this subject: identify the space, representation, and approximation before trusting the number that comes out.
Read the Introduction when the names and relationships need a full map. Use Slides for the compact comparison of spaces, rotations, cameras, and collision tests. Keep the Cheatsheet beside implementation work for formulas and failure signals. The Practice Reference turns those formulas into worked calculations, and the exercise joins them into one steering behavior. That is enough to make the engine's math helpers feel less like ceremonial buttons and more like tools with consequences.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://docs.unity3d.com/ScriptReference/Quaternion.html
Supports
- Quaternions are a four-component (x, y, z, w) rotation representation
- Quaternions avoid gimbal lock and interpolate smoothly, unlike Euler angles
- Quaternions can concatenate a series of rotations into one representation
- Quaternions should not be edited component-by-component and must stay normalized
- Quaternion.Euler and Quaternion.AngleAxis build quaternions from angle representations
- https://docs.unity3d.com/ScriptReference/Quaternion.Slerp.html
Supports
- Slerp spherically interpolates between two unit quaternions by a clamped ratio t
- Slerp produces a smooth rotation between a start and end quaternion
- https://docs.unity3d.com/ScriptReference/Quaternion.AngleAxis.html
Supports
- Quaternion.AngleAxis builds a rotation from a degree angle and an axis vector
- https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
Supports
- Lerp formula: V = A + (B - A) * t, with t clamped to the 0-to-1 range
- https://docs.unity3d.com/Manual/CollidersOverview.html
Supports
- Primitive, mesh, and wheel colliders are the main collider shape categories
- https://docs.unity3d.com/Manual/PhysicsOverview.html
Supports
- A collision occurs when the physics engine detects that two colliders make contact or overlap and at least one has a moving Rigidbody
- https://docs.unity3d.com/6000.3/Documentation/Manual/UnderstandingFrustum.html
Supports
- The view frustum is a pyramid with its top cut off, defining the region a perspective camera renders
- Orthographic cameras keep object size constant with distance; perspective cameras shrink distant objects
- Field of view is the angle subtended by lines converging from the top and bottom of the screen at the camera's viewpoint
- Near and far clip planes bound the rendered distance range
- Frustum culling excludes renderers outside the camera's view frustum
- https://docs.godotengine.org/en/stable/tutorials/math/vector_math.html
Supports
- Vectors represent direction and magnitude with no inherent position
- Vector addition combines components directly; scalar multiplication changes magnitude, not direction, for positive scalars
- Normalization divides each component by the vector's magnitude to reach length 1
- Dot product of unit vectors ranges from -1 to 1 and reflects the angle between them; it is commutative
- Cross product returns a perpendicular vector and is order-dependent (anticommutative)
- Movement is computed by adding scaled velocity to position; direction from A to B is B minus A
- https://docs.godotengine.org/en/stable/tutorials/math/matrices_and_transforms.html
Supports
- A transform's basis vectors represent rotation and scale; the origin vector represents position
- Scaling a transform multiplies each basis vector's components by the scale factor
- 2D rotation is built from cosine on the diagonal and sine off-diagonal, with one entry negated
- Godot represents all rotations in radians, not degrees
- Translating a transform means changing its origin vector
- Matrix multiplication order matters; world_transform = parent * child
- transform * vector converts local to world space; vector * transform converts world to local
- 3D rotation uses quaternions rather than a single angle because of added complexity
- https://docs.godotengine.org/en/stable/tutorials/3d/using_transforms.html
Supports
- A node's local transform is relative to its parent; global_transform gives the world-space transform
- A transform's basis consists of three vectors describing rotation, and its origin is a position vector
- Combining basis and origin represents a unique translation, rotation, and scale
- https://dev.epicgames.com/documentation/unreal-engine/API/Runtime/Core/TQuat?lang=en-US
Supports
- FQuat/TQuat components (x, y, z, w) double as axis/angle rotation data
- Quaternion composition C = A * B applies B first, then A, which is the opposite order of FTransform multiplication
- https://dev.epicgames.com/documentation/en-us/unreal-engine/BlueprintAPI/Math/Quat/RotateVector_Quat
Supports
- A quaternion can rotate a vector, taking the quaternion and the vector as input and returning the rotated vector
- https://www.scratchapixel.com/lessons/mathematics-physics-for-computer-graphics/geometry/math-operations-on-points-and-vectors.html
Supports
- Dot product formula: A . B = Ax*Bx + Ay*By + Az*Bz, equal to the cosine of the angle between unit vectors
- Cross product formula: component-wise construction of a vector perpendicular to both inputs, anticommutative
- Vector normalization divides by vector length to produce a unit vector, with a zero-length guard
- https://developer.mozilla.org/en-US/docs/Games/Techniques/3D_collision_detection
Supports
- AABB intersection test compares min/max ranges on every axis
- Sphere-vs-sphere intersection compares the distance between centers against the sum of radii
- Sphere-vs-AABB intersection clamps the sphere center to the box bounds to find the closest point, then compares distance to radius
- Comparing squared distance to squared radius avoids computing a square root
- Bounding spheres are rotation-invariant; AABBs are cheaper to test but must be recomputed after rotation
- https://en.wikipedia.org/wiki/Gimbal_lock
Supports
- Gimbal lock occurs when two rotation axes become parallel, losing one degree of freedom
- Gimbal lock affects Euler-angle rotation representations; quaternions and rotation matrices avoid it
- https://www.khanacademy.org/math/algebra2/x2ec2f6f830c9fb89:trig/x2ec2f6f830c9fb89:unit-circle/v/unit-circle-definition-of-trig-functions-1
Supports
- On the unit circle, a point's x-coordinate is the cosine and y-coordinate is the sine of its angle
- https://www.khanacademy.org/math/algebra2/x2ec2f6f830c9fb89:trig/x2ec2f6f830c9fb89:radians/v/introduction-to-radians
Supports
- A radian measures an angle by the arc length it cuts out of a circle of that radius; one full turn equals 2 pi radians
- https://learnopengl.com/Getting-started/Transformations
Supports
- Matrix multiplication is not commutative (A times B does not equal B times A)
- Translation is added via the fourth column of a transformation matrix
- Combining scale, rotate, and translate into one matrix is done through matrix multiplication, applied scale then rotate then translate
- https://realtimecollisiondetection.net/
Supports
- The site is a reference and errata companion for a widely cited real-time collision detection reference text
- https://github.com/g-truc/glm
Supports
- GLM is a header-only C++ mathematics library mirroring GLSL syntax, licensed under the MIT/Happy Bunny license, used for graphics, physics, and image-processing math
- https://libeigen.gitlab.io/
Supports
- Eigen is a C++ template library for linear algebra (matrices, vectors, numerical solvers), licensed under MPL2
- https://github.com/microsoft/DirectXMath
Supports
- DirectXMath is an all-inline SIMD C++ linear algebra library for games and graphics apps, licensed under MIT, supporting SSE/SSE2 and ARM-NEON
- https://cglm.readthedocs.io/
Supports
- cglm is a header-only, MIT-licensed C math library for graphics programming, using SIMD-aligned vec4/quaternion/mat4 types
- https://docs.unity3d.com/Packages/com.unity.mathematics@latest
Supports
- Unity.Mathematics provides SIMD-friendly float3/float4 vector types and quaternion functions recognized by the Burst compiler, licensed under the Unity Companion License
- https://github.com/bulletphysics/bullet3
Supports
- Bullet is an open-source, zlib-licensed collision detection and rigid/soft body dynamics library used in games, VR, robotics, and visual effects
- https://box2d.org/
Supports
- Box2D is a free, open-source 2D rigid-body physics engine written in C, MIT-licensed since version 2.4.0, created by Erin Catto
- https://developer.nvidia.com/physx-sdk
Supports
- NVIDIA PhysX has been open source (BSD-3 license) since SDK 4.0 in December 2018, with GPU simulation source code later included as well
- https://www.havok.com/pricing/
Supports
- Havok's pricing model charges a flat per-title fee (50,000 USD) with no royalty for titles with per-title budgets up to 20 million USD
- https://github.com/jrouwe/JoltPhysics
Supports
- Jolt Physics is a multi-core-friendly, MIT-licensed rigid body physics and collision detection library used by Horizon Forbidden West and Death Stranding 2, replacing a commercial physics engine
- https://chipmunk-physics.net/
Supports
- Chipmunk2D is a fast, lightweight, MIT-licensed 2D rigid body physics library written in C
- https://github.com/recastnavigation/recastnavigation
Supports
- Recast builds a navigation mesh from input geometry via voxelization and region generation; Detour provides pathfinding and spatial reasoning over that navmesh, zlib-licensed
- https://www.reactphysics3d.com/
Supports
- ReactPhysics3D is a C++ physics engine using a dynamic AABB tree for broadphase and SAT/GJK for narrowphase collision detection, with rigid body dynamics and a sequential impulses solver, zlib-licensed
- https://github.com/danfis/libccd
Supports
- libccd implements the GJK algorithm with an EPA extension for penetration depth, plus the MPR (XenoCollide) algorithm, for collision detection between convex shapes, BSD-licensed, used inside ODE, FCL, and Bullet
- https://www.cgal.org/
Supports
- CGAL is a C++ library of computational geometry algorithms including triangulations, Voronoi diagrams, boolean operations on polygons/polyhedra, and mesh generation, dual-licensed under GPL v3+ and a commercial license
- https://www.boost.org/doc/libs/latest/libs/geometry/doc/html/index.html
Supports
- Boost.Geometry provides distance calculations, intersection detection, spatial indexing (R-trees), and other geometric algorithms as a C++ library
- https://github.com/flexible-collision-library/fcl
Supports
- FCL performs collision detection, minimum-distance computation, and continuous collision detection between geometric models composed of triangles, boxes, spheres, and other shapes
- https://docs.godotengine.org/en/stable/tutorials/physics/interpolation/physics_interpolation_introduction.html
Supports
- Fixed-rate physics improves consistency and predictability when rendered frames vary.
- Interpolating between prior and current physics transforms smooths rendering but displays a past state and can add input delay.
- https://gafferongames.com/post/fix_your_timestep/
Supports
- A fixed timestep keeps numerical integration steps bounded and supports more predictable game physics.
- https://www.gamedeveloper.com/design/postmortem-gas-powered-games-i-dungeon-siege-i-
Supports
- Dungeon Siege developers reported that implicit coordinate-system rules introduced nonobvious bugs and costly maintenance.
