Mathematics matters in video games because a game world has to keep track of where objects are, how they move, when they overlap and what should happen next. Coordinates locate a character. Vectors describe direction and speed. Inequalities decide whether shapes collide. Time steps connect motion with the frames drawn on screen.
For students asking why mathematics is important in computing, a tiny two-dimensional game provides an inviting answer. The artwork may create the world, but relationships make it behave consistently. A character that travels at the same intended speed on different computers needs time-aware movement. A ball that bounces from a wall needs geometry, not a guess based on appearance.
This article builds original paper models rather than a complete commercial game. Its characters, positions and dimensions are fictional. Different engines use different coordinate conventions, units and physics systems, so official documentation for the chosen tool should guide actual implementation. The learning goal is to understand the mathematics well enough to explain and test the behaviour.
Choose the game question you want to solve
- Locate an object: connect pixels and ordered pairs.
- Move consistently: combine direction, speed and time.
- Detect contact: turn shapes into testable inequalities.
- Respond to contact: separate detection from response.
- Build a project: model, test and debug a small world.
Coordinates turn a screen into a mathematical space
Choose an origin and two axes. In many two-dimensional graphics systems, the origin is at the top left, x increases to the right and y increases downward. This differs from the classroom Cartesian plane, where positive y usually points upward.
The Godot Engine vector mathematics documentation explicitly describes the top-left convention and represents a 2D position using a pair such as (400, 300). The convention is not a new kind of mathematics; it is a definition for interpreting the coordinate pair.
Suppose a fictional character is at (120, 80). Moving 30 pixels right and 15 pixels down gives (150, 95) under this convention. If the same numbers were interpreted on an upward-positive classroom axis, the vertical story would be different.
This teaches a durable habit: never use coordinates without defining the frame. The ordered pair does not carry its origin, axis directions or unit inside the numbers. Those belong to the model's contract.
Position and displacement are related but different
A position identifies where an object is relative to the chosen origin. A displacement describes a change from one position to another. If a player moves from (20, 40) to (70, 55), the displacement is (70 − 20, 55 − 40) = (50, 15).
Adding the displacement back to the starting position returns the endpoint: (20, 40) + (50, 15) = (70, 55). Subtracting in the opposite order gives (−50, −15), the displacement from the endpoint back to the start.
Godot's documentation describes a vector as direction and magnitude independent of where the arrow is drawn. The same displacement (50, 15) can move many objects by the same relative amount even when their starting positions differ.
This is why vector language helps. It separates “where the character is” from “how the character changes position”. Both may be stored as coordinate pairs, but their meanings are not identical.
Magnitude measures the length of a vector
For a vector (3, 4), its magnitude is √(3² + 4²) = 5. This is Pythagoras' theorem applied to horizontal and vertical components. The vector carries direction through its component signs and length through its magnitude.
Consider displacements (6, 0) and (3.6, 4.8). Both have magnitude six, but they point in different directions. Equal distance does not mean equal endpoint unless the starting point and direction also agree.
Did you know? A character controlled with separate right and down inputs can move faster diagonally if each axis receives a full-speed value. The vector (1, 1) has magnitude √2, not one. Normalising the direction before applying the chosen speed can prevent this unintended boost.
Magnitude is also useful for circle collision, target distance and arrival tests. The same school geometry travels naturally into game development once the coordinates have a clear meaning.
Normalisation keeps direction while changing length
To normalise a non-zero vector, divide each component by its magnitude. Normalising (3, 4) gives (3/5, 4/5), or (0.6, 0.8). The new magnitude is √(0.6² + 0.8²) = 1.
Multiplying this unit direction by a speed of 100 pixels per second gives velocity (60, 80) pixels per second. The direction stays the same while its length becomes the desired speed.
A zero vector has no direction and cannot be normalised by dividing by its magnitude, because its magnitude is zero. Actual engines may define a safe behaviour for this case; learners should check the tool's documentation rather than assume division by zero is meaningful.
The mathematical advantage is control. Input determines direction, while a separate scalar determines speed. Changing speed no longer changes the intended direction accidentally.
Velocity needs an elapsed time
Velocity expresses displacement per unit time. If a character travels at (60, 80) pixels per second for 0.25 seconds, its displacement is (15, 20) pixels. From starting position (100, 50), the new position is (115, 70).
The formula is new position = old position + velocity × elapsed time. Godot's official guide uses this same relationship and notes that games commonly multiply pixel-per-second velocity by the time since the previous frame.
Without the time factor, adding (60, 80) every frame would make motion depend on the number of updates. At 60 updates per second, the character would move 60 times the intended per-second displacement. On another machine or during a slowdown, behaviour could change again.
Units expose the correct operation: pixels/second × seconds = pixels. A vector per frame is another possible design, but then its unit and dependence on frame rate must be understood rather than silently mixed with pixels per second.
Frame rate is a sampling schedule, not the speed itself
At 100 pixels per second, a perfectly even 60-frame-per-second model moves 100/60 ≈ 1.667 pixels per frame. At 50 frames per second, it moves 2 pixels per frame. Over one second, both accumulate to 100 pixels when elapsed time is handled correctly.
The two sequences do not draw identical intermediate positions because their sample times differ. Equal total displacement does not mean equal visual smoothness. Rendering, input sampling and physics updates can operate on related but different schedules.
Suppose four time steps are 0.016, 0.017, 0.015 and 0.018 seconds. Their total is 0.066 seconds. A 120-pixel-per-second object should move 7.92 pixels across those steps, not exactly four times one assumed frame displacement.
This is a practical use of decimals and accumulation. The learner can sum time first and multiply once, then compare with multiplying each step and adding. Agreement becomes an independent check.
Acceleration changes velocity over time
Velocity changes position; acceleration changes velocity. In a simple constant-acceleration time step, new velocity can be approximated as old velocity + acceleration × elapsed time.
Let downward acceleration be (0, 200) pixels per second squared. Starting vertical velocity is zero. After 0.10 seconds, the velocity update adds 20 pixels per second downward. A second equal step adds another 20, producing 40 pixels per second.
The position update depends on the numerical integration method and the order in which velocity and position are updated. Different simple methods produce slightly different approximations. A real engine documents its physics behaviour; a paper activity should state its chosen rule.
This limitation is educationally useful. Mathematics does not merely provide one magic formula. It helps the designer specify how continuous motion is approximated by discrete updates and study the error created by that choice.
A bounding box simplifies a complex sprite
A character image may contain an irregular outline, transparent pixels and animation. Testing every visible pixel against every other image could be expensive and unnecessary. Games often use simpler collision shapes such as rectangles or circles.
MDN's 2D collision-detection guide describes a generic covering shape as a hitbox and notes the tradeoff between exact visual matching and performance. A hitbox is a model of the interactive region, not the artwork itself.
Imagine a 40-by-60-pixel character sprite with a 28-by-52 hitbox centred inside it. The smaller box may exclude decorative hair or a cape. Whether that feels fair depends on the game purpose and interaction, not on geometry alone.
The designer should make the simplification visible during testing. A mathematically correct hitbox can still feel wrong if it does not match the player's expectation of contact.
Two axis-aligned rectangles collide when their intervals overlap
Represent rectangle A by horizontal interval [A_left, A_right] and vertical interval [A_top, A_bottom]. Rectangle B has matching intervals. For an overlap with positive area, the horizontal intervals must overlap and the vertical intervals must overlap.
MDN expresses this through four inequalities: A's left is before B's right, A's right is after B's left, A's top is before B's bottom, and A's bottom is after B's top. All must be true for the strict-overlap convention shown there.
Let A occupy x from 10 to 30 and y from 20 to 50. Let B occupy x from 25 to 40 and y from 45 to 65. Their horizontal overlap is 30 − 25 = 5 pixels and vertical overlap is 50 − 45 = 5 pixels, so the rectangles overlap.
If B moves to x from 31 to 46, there is a one-pixel horizontal gap. Vertical overlap remains, but collision is false because separation on either axis is enough to keep rectangles apart.
Touching and overlapping need a declared rule
Suppose A's right edge is x = 30 and B's left edge is also x = 30. Do they collide? Geometry says the closed rectangles share a boundary line, but a game may reserve “collision” for positive-area overlap or may count touching as contact.
Using strict inequalities can treat exact edge contact differently from using inclusive inequalities. Floating-point rounding and engine-specific contact tolerances can add further complexity. The correct choice depends on the intended behaviour and documented physics system.
A platformer may want a character standing on a platform to count as grounded even without visible penetration. A trigger zone may activate only after its interior is entered. These are design rules expressed through mathematics.
Students should test the boundary case explicitly. An algorithm that works for obvious overlap but fails at exact contact has not yet been fully specified.
Circle collision uses centre distance and radii
Two circles with centres A and B and radii r₁ and r₂ overlap when the distance between centres is less than the sum of the radii. MDN presents this common circle-collision rule.
Let the first centre be (2, 3) with radius 4 and the second be (8, 6) with radius 3. The centre displacement is (6, 3). Its squared distance is 6² + 3² = 45. The squared sum of radii is 7² = 49. Because 45 < 49, the circles overlap under a strict test.
Comparing squared quantities avoids calculating the square root. This preserves the result because both sides are non-negative and squaring is order-preserving there. It is an optimisation derived from mathematical equivalence.
If squared distance equals 49, the circles touch at one point. Again, the designer must decide whether touching counts as collision for the particular interaction.
Distance checks can create interaction zones
A game may ask whether a player is close enough to open a door or collect an object. If the interaction radius is 50 pixels, compare the squared centre distance with 2,500.
From player (100, 80) to object (130, 120), displacement is (30, 40) and distance is 50. Under an inclusive rule, the player is exactly in range. Under a strict less-than rule, the boundary would not activate.
A circular interaction zone may feel natural around a point but wrong around a long object. A rectangle, capsule or distance to a line segment could better represent another design. The mathematical shape is a modelling choice.
This is why learning geometry transfers beyond solving textbook diagrams. Students learn to choose a representation whose boundary matches the question being asked.
Detection and response are different problems
Collision detection answers whether and where shapes meet. Collision response decides what happens: stop, slide, bounce, lose health, trigger a sound or pass through after recording an event.
If a ball overlaps a wall, simply reversing its velocity may make it appear to bounce, but the ball may remain embedded and reverse again on the next step. The engine or algorithm must also resolve the position or calculate the time of contact.
A trigger can detect overlap without exerting a physical force. Conversely, a wall can block motion without creating a game score event. Keeping detection and response separate makes the program easier to reason about and test.
This distinction resembles mathematics elsewhere: identifying that a condition is true differs from choosing a decision based on it. The test provides evidence; the design supplies the consequence.
A wall bounce changes one velocity component
For a vertical wall, the surface normal is horizontal. In a simple ideal bounce, the horizontal velocity component changes sign while the vertical component stays the same.
A ball arriving with velocity (120, 30) pixels per second could leave with (−120, 30) in an ideal perfectly elastic teaching model. Its speed remains √(120² + 30²), but its horizontal direction reverses.
For a horizontal floor, vertical velocity changes sign instead. A damping factor can reduce the reflected component: with factor 0.75, downward velocity 80 could become upward velocity 60 in magnitude under the chosen convention.
Godot's vector guide explains reflection using a surface normal. Actual engine response depends on materials, bodies and settings. The paper model demonstrates component reasoning, not a universal game-physics rule.
Reflection across a general surface uses a normal
Let v be an incoming velocity and n a unit normal. A standard reflection relationship is r = v − 2(v · n)n. The dot product measures the part of v aligned with the normal.
For v = (3, −4) and an upward normal n = (0, 1), v · n = −4. Then r = (3, −4) − 2(−4)(0, 1) = (3, 4). Only the vertical component changes, matching the simpler wall reasoning.
If n is not a unit vector, the formula needs adjustment or prior normalisation. This is a good example of a condition attached to a formula. Memorising the symbols without the unit-normal requirement can produce a wrong result.
Students can verify reflected speed in the ideal model. Both (3, −4) and (3, 4) have magnitude five. Conservation in this simplified bounce is evidence that the calculation is internally consistent.
The dot product can test which way an object faces
For unit vectors, the dot product equals the cosine of the angle between them. A positive result means the angle is less than 90 degrees, zero means perpendicular, and negative means more than 90 degrees.
Suppose an enemy faces unit direction (1, 0). The unit direction from enemy to player is (0.8, 0.6). Their dot product is 0.8, so the player lies generally in front. If the direction were (−0.8, 0.6), the result would be −0.8, generally behind.
A field of view narrower than 180 degrees uses a larger threshold. For a half-angle of 45 degrees, compare with cos 45°, approximately 0.707. The 0.8 direction is inside that angular cone.
Visibility also requires distance and obstruction checks. One positive dot product does not prove that a wall is absent. A well-designed model combines the conditions it actually needs.
Randomness is a distribution, not “anything can happen”
A game may choose a reward from several outcomes. If a fictional spinner has probabilities 0.5, 0.3 and 0.2, they sum to one. Over many independent spins, observed proportions may approach those probabilities, but a short run can vary.
In ten spins, receiving a rare 0.2 outcome zero times is possible. Receiving it exactly twice is not guaranteed. Probability describes a model of repeated uncertainty rather than a schedule promising one rare reward in every block of five.
If a designer instead guarantees one outcome per five-item bag, the mechanism is different from independent selection. The long-run percentages may match while short-run behaviour changes.
This connects games with the interpretation developed in Why Mathematics? | Comparing Percentages Fairly. The denominator and selection rule matter as much as the displayed percentage.
Scores are functions of events
Suppose coins are worth 10 points, targets 25 and completion gives 100. A run with 7 coins, 3 targets and completion scores 7 × 10 + 3 × 25 + 100 = 245.
The formula compresses a rule system. Changing target value to 30 changes the same event record to 260. The player did not perform differently; the scoring function changed.
This matters when comparing versions or balancing a game. A higher score can result from better play, different opportunity, different duration or altered weights. Raw totals need context before they become evidence of skill.
A spreadsheet can model these scenarios, linking naturally to Why Mathematics? | Spreadsheets, Formulas and Reliable Decisions. The sheet owns the reusable calculation; the game model supplies its events and rules.
Interpolation creates a position between positions
Linear interpolation between A and B uses A + t(B − A), where t ranges from zero to one. At t = 0 the result is A; at t = 1 it is B; at t = 0.25 it is one-quarter of the way from A to B.
Let A = (20, 10) and B = (100, 50). Their difference is (80, 40). At t = 0.25, the interpolated position is (20, 10) + (20, 10) = (40, 20).
Equal changes in t produce equal spatial steps along a straight segment. If a designer wants easing, a separate function can transform time before interpolation. The path and timing profile are distinct choices.
Interpolation can smooth display or animate an interface, but it does not automatically reconstruct the true path between sparse observations. A visually smooth curve is still a model.
Camera transformations change the view, not the world
A world coordinate can be converted to a screen coordinate by subtracting the camera position and applying scale or rotation. If a world object is at x = 500 and the camera's left edge corresponds to world x = 420, the object's basic screen x is 80 before other transformations.
When the camera moves right by 20 while the object stays fixed, its screen coordinate becomes 60. The object appears to move left even though its world coordinate did not change.
This is a powerful distinction between representation and state. Debugging becomes easier when a student asks whether the object's world position changed or only its displayed position after a camera transformation.
The same idea appears in maps and graphs: a change of viewpoint or scale can alter appearance without altering the underlying object. Mathematics makes the transformation explicit.
Continuous collision matters for fast objects
Imagine a thin wall occupying x from 50 to 52. A small object is at x = 40 on one update and x = 60 on the next. Testing overlap only at those two positions can miss the wall even though the path crosses it.
This is sometimes called tunnelling. One response is to test the swept path or calculate a possible time of impact. Another is to use smaller time steps. Each choice has accuracy and computation tradeoffs.
A simple one-dimensional calculation asks when a point moving from 40 to 60 reaches x = 50. The fraction is (50 − 40)/(60 − 40) = 0.5, halfway through the step. That information can support a more accurate response.
Actual engines provide specific collision modes and limitations. Students should use the tool's current documentation. The mathematical lesson is that sampling endpoints can miss events occurring between them.
Numerical error accumulates unless it is checked
Computers approximate many real numbers with finite representations. Repeated additions can produce small differences from an ideal decimal calculation. A game can also accumulate logical error if time steps or units are mixed.
Suppose an object should travel 0.1 units per step for ten steps. The mathematical sum is one. A computer representation may display a nearby value, depending on number format and operations. This does not make arithmetic useless; it means tests should use appropriate tolerances.
Do not fix every mismatch by accepting an enormous tolerance. A tolerance should reflect numerical scale and purpose. A five-pixel allowance in a one-pixel puzzle can change the game rule itself.
Students can compare exact fractions with decimal approximations and record the difference. Debugging becomes an investigation into representation, not a search for someone to blame.
Fixed and variable time steps make different promises
A variable-step update uses the elapsed time reported for each frame. This is convenient for visible movement because distance remains tied to time even when rendering speed changes. Physics simulation can become harder to reproduce if every step has a different length. A fixed-step update instead advances the model in equal slices, perhaps 1/60 second at a time, while the screen may draw at another rate. Neither approach is automatically superior; the decision depends on the behaviour being modelled and the consistency required.
Consider a character accelerating at 6 m/s² for one second from rest. A simple school model using ten equal 0.1-second updates changes velocity by 6 × 0.1 = 0.6 m/s each step, reaching 6 m/s. If a program accidentally treats every frame as 0.1 seconds while actually producing only eight frames, it simulates only 0.8 seconds of motion. If it produces twelve, it simulates 1.2 seconds. Labelling the time step and checking total elapsed time prevents frame count from silently becoming the clock.
A grid can turn movement into a path problem
Many puzzle and strategy games divide a level into cells. A cell can be open, blocked or costly to cross. The map becomes a network: cells are positions and legal moves are connections. Mathematics helps the designer distinguish straight-line distance from travel cost. A treasure may be only four squares away geometrically but require a ten-step route around a wall. A swamp cell might count as three cost units while an ordinary cell counts as one.
Take two possible routes. Route A uses eight ordinary cells, so its cost is 8. Route B uses five ordinary cells and two swamp cells, so its cost is 5 + 2 × 3 = 11. Route A is longer in cell count but cheaper under this rule. If the character can move diagonally, the designer must decide whether a diagonal costs 1, √2, or another value. Each rule changes the strategies the game rewards. The mathematical model is part of the design, not merely background code.
Tests should check properties as well as pictures
A screenshot can look plausible while the underlying rule is wrong. Strong tests express properties that should remain true. A normalised non-zero direction should have length approximately 1. Moving at zero velocity should not change position. Reflecting from a perfectly vertical wall should reverse the horizontal component but preserve the vertical one in the simplified elastic model. A score should change only when its declared event occurs. These are mathematical invariants: statements intended to survive many inputs.
Students can build a test table with input, prediction, output and explanation. For a circle-collision rule, include clearly separate circles, clearly overlapping circles, exact touching, coincident centres and one very large radius. For movement, try delta = 0, a small positive delta and two half-steps that should equal one full step under constant velocity. Edge cases reveal what the rule actually says and whether the program says the same thing.
A student project: make a paper game engine
Draw a 600-by-400 coordinate world on graph paper at a manageable scale. Place a player rectangle, two circular targets and one rectangular wall. Record every shape by coordinates and dimensions.
Give the player a velocity vector and a time step. Calculate three positions. At each step, test the player rectangle against the wall using interval overlap and test its centre against each target using squared distance.
Add one deliberate boundary case: exact contact with the wall or target. State whether contact counts. Then change frame duration while keeping velocity in units per second and verify that total motion over equal time remains consistent.
The finished report should show inputs, units, formulas, two checks and limitations. Artwork is welcome, but the project succeeds when another student can reproduce the behaviour from the mathematical specification.
A second project: debug a diagonal-speed problem
Create four raw input directions: right (1, 0), down (0, 1), down-right (1, 1) and no input (0, 0). Calculate their magnitudes.
The diagonal input has magnitude √2. Normalise all non-zero directions and multiply by a chosen speed, perhaps 120 pixels per second. The right and diagonal velocities now both have magnitude 120 even though their components differ.
Run each for half a second. Compare total distance. Add a guard for the zero vector rather than dividing by zero. Explain why the repair changes diagonal movement but preserves its direction.
This project turns a familiar “the character feels too fast” observation into a precise diagnosis, a mathematical fix and a test that can fail or pass.
Parent guidance: ask the child to predict one frame
Begin with a paper grid and one position. Ask, “If this velocity lasts half a second, where should the character go?” Prediction keeps the mathematics active before any engine displays an answer.
If vectors feel abstract, draw arrows and measure them. If collision inequalities feel confusing, use strips representing horizontal and vertical intervals. Two rectangles collide only when both pairs overlap under the chosen rule.
Praise explanations that survive a change. Can the learner adjust for a different frame time, radius or wall position? Transfer is stronger evidence than replaying one memorised example.
For connected foundations, use the Mathematics Learning Hub. Coordinates, Pythagoras' theorem, rates, equations, inequalities and probability all appear naturally in this one playful setting.
Learning and careers should remain open
Game creation can combine mathematics, computing, visual art, writing, sound and design. One person may focus on gameplay programming, another on animation, interface, narrative, audio or testing. Teams and roles vary.
The mathematics here describes activities that can appear in development. It does not mean every games role uses every formula daily, or that studying one project guarantees access to an industry. Programming practice, communication, portfolios and specialised knowledge matter too.
For a broader explanation of disciplines working together, read How School Works | School Subjects Explained. It keeps the connection genuine without collapsing art, computing and mathematics into the same subject.
A student who enjoys the project can notice which question attracts them: motion, collision, probability, level design or visual communication. That curiosity can guide the next experiment while future pathways stay flexible.
Questions students and parents often ask
Do game developers calculate everything by hand?
Engines provide vector, collision and physics tools. Understanding the mathematics helps a developer choose settings, interpret documentation, predict behaviour and diagnose results. Tools reduce repeated implementation; they do not define the intended game automatically.
Why does the y-axis sometimes point down?
It is a graphics coordinate convention. The mathematics remains consistent once the origin and axis directions are declared. Convert carefully when moving between systems with different conventions.
Is a hitbox supposed to match every visible pixel?
Not always. Simpler shapes can be faster and may produce better play. The chosen hitbox should fit the interaction and be tested for fairness and clarity.
Does touching count as collision?
That depends on the algorithm and design rule. Inclusive and strict inequalities treat the boundary differently. Specify the rule and test exact contact.
Why can a fast object pass through a wall?
Discrete updates may observe the object before and after the wall without testing the swept path. Continuous collision methods or smaller time steps can address the problem, subject to the engine's design.
What should a student learn next?
Practise vectors, rates and interval overlap in a two-dimensional model. Then add acceleration, dot products or swept motion only after the simpler relationships are stable.
Mathematics gives play a dependable world
A game feels free, but its world needs rules. Coordinates establish place. Vectors create motion. Geometry decides contact. Probability creates controlled uncertainty. Functions turn events into scores.
The importance of mathematics is not that it replaces creativity. It gives creative choices a dependable structure that another person—and a computer—can execute. A well-designed rule can be playful precisely because its behaviour is clear enough to learn, test and vary.
The most transferable skill is moving between representations. A student should describe a rule in words, draw it on a coordinate grid, calculate a test case, express it as a condition and compare the result with observed behaviour. When those representations disagree, the mismatch becomes a useful debugging question. This habit reaches beyond games into engineering, computing, science and any field where a model must survive contact with evidence.
Start small enough to inspect every number. One moving point, one wall and one declared time step can teach more than a complicated project whose rules remain hidden. Once the simple case works, change one assumption at a time and record the effect. Curiosity becomes disciplined experimentation, and mathematics becomes a creative tool for making worlds that are surprising on purpose rather than inconsistent by accident.
Start with one character, one velocity and one wall. Predict, calculate, draw and debug. The moment a learner explains why the diagonal was faster or why two boxes did not overlap, school mathematics has become a tool for building an interactive idea.
