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
Intro
Game Mathematics
Game mathematics is the set of vector, trigonometry, matrix, and geometry
techniques that determine where objects are, which way they face, how they
move, and whether they touch. A game engine exposes this layer through
classes such as Godot's Vector3 and Transform3D, Unity's Vector3 and
Quaternion, or Unreal Engine's FVector and FTransform. Underneath those
classes, the same mathematical operations recur across every engine:
addition, dot products, cross products, matrix composition, and rotation
interpolation. Understanding that shared layer lets you read engine
documentation critically, debug incorrect movement or rotation, and choose
the right representation for a given problem instead of copying a snippet
that happens to work.
Coordinate spaces and vectors
A vector represents a magnitude and a direction, stored as coordinates such
as (x, y) in 2D or (x, y, z) in 3D. A vector carries no position of its
own; the same vector (3, 0) can describe a displacement starting from any
point in the world. Godot's documentation states plainly that vectors "only
represent relative direction and magnitude," which is why a velocity vector
and a position vector use the same data type but mean different things
depending on how the game code uses them.
Games work with several coordinate spaces at once:
- Local (or object) space places coordinates relative to an object's own origin and orientation.
- World (or global) space places coordinates relative to one shared origin for the whole scene.
- Screen space places coordinates relative to the rendered viewport, after the camera's projection has been applied.
An object's transform converts its local-space geometry into world space so the renderer and physics system can compare it against everything else in the scene.
Core vector operations
Continue the course
This section is part of the paid course.
See pricing to subscribe, or log in if you already have access.
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
