Grades 9–12 · Computing
How does a video game know when two things collide?
A character can stand on a drawn platform because the game maintains an invisible geometric model alongside the picture. The platform may look like rough stone, but its collision shape can be a simple rectangle. The character may use a capsule or box. These shapes make contact tests manageable without examining every visible pixel or decorative triangle.
A simulation advances in time steps. For two axis-aligned rectangles, a basic overlap test checks whether their horizontal intervals overlap and whether their vertical intervals overlap. Both must overlap for their interiors to intersect. More detailed systems first find nearby candidates, then perform narrower geometric tests on those candidates. Rules determine whether a pair should interact at all.
The upper row shows endpoint tests; the lower row includes the space traversed between them.
Detecting contact is only the first decision. The game must choose a response: stop movement, slide along a surface, bounce, collect an item, or trigger an event without blocking motion. A contact normal describes the direction perpendicular to the surface and helps compute that response. The same geometric overlap can therefore produce different behavior in different games.
Time steps introduce a subtle problem. A small, fast object can be on one side of a thin wall at one step and entirely beyond it at the next. Neither sampled position overlaps the wall, so a position-only test can miss the crossing. Continuous collision detection instead checks the motion between positions, often by sweeping a simple shape along its proposed path and looking for the first contact.
More detailed checks cost computation, and simpler shapes can give imperfect matches to the artwork. Developers choose accuracy where it matters: a fast projectile may need a sweep while a slow decorative object does not. What feels like a solid world is a repeated agreement between geometry, timing and rules for what happens at contact.
About this explanation
The drawing illustrates tunneling in a simplified two-dimensional model; engines use multiple collision algorithms and response rules.
Starting knowledge: Understand coordinates, intervals and motion over a time step.
Sources
- Godot Engine — Using CharacterBody2D/3D
- Godot Engine — RigidBody2D: continuous collision detection