The Science of Hitboxes and Collision Detection: How Raycasting and AABBs Decide Virtual Life and Death
Every landed punch and missed headshot relies on invisible geometry. Here is how game engines calculate collision detection, balancing computational cost against pixel-perfect accuracy.
By Omar Haddad
- Engine Architects
- Prioritizing computational efficiency and stable frame rates over pixel-perfect physical accuracy.
- Fighting Game Developers
- Using distinct hitboxes and hurtboxes as a balancing tool rather than a strict physical simulation.
- Tactical Shooter Designers
- Relying on instantaneous raycasting and capsule colliders to create crisp, responsive gunplay.
A fighting game grand final is often decided by a single pixel. The screen freezes on a crucial strike. The sword visually passes through the opponent's arm, but no damage is registered. The crowd roars in confusion, commentators scramble for an explanation, and the attacking player drops their controller in disbelief. This is not a glitch; it is the cold, mathematical reality of collision detection.
Every time a sword swing connects, a bullet lands, or a platforming jump just barely clears a ledge, the game engine is asking the same silent question: did this shape touch that shape? The answer comes from hitboxes, the invisible geometry that defines interactive space and dictates the rules of virtual physics.[3][5]
The visible character model—the high-resolution mesh with thousands of polygons, intricate armor, and flowing fabric—is just a costume. The actual body that the game engine cares about is built from primitive mathematical shapes. Understanding how these shapes work unlocks a layer of design that most players feel but never see.[5]
The reason developers do not use the visible character model for collision detection comes down to raw computational cost. If a game has thousands of bodies in a simulation, checking every polygon against every other polygon creates a computational complexity of O(n²). The number of pairwise tests increases quadratically, which would instantly grind the engine to a halt.[1]
In a modern game running at 60 frames per second, the CPU has just 16.6 milliseconds to calculate physics, artificial intelligence, player input, and rendering. Calculating mesh-accurate collisions for thousands of objects is impossible within this strict budget. To survive, developers cut corners hard by using simplified bounding volumes.[6]
Instead of complex meshes, engines rely on simple shapes. The most common is the Axis-Aligned Bounding Box (AABB). An AABB is a simple rectangle or cube that remains perfectly aligned with the world's X, Y, and Z axes, regardless of what the character inside it is doing.[2][4]
Checking for an AABB collision is incredibly fast. The engine simply checks if the intervals along each axis overlap. If the right edge of Box A is past the left edge of Box B, and their vertical axes also intersect, a collision is registered. It requires only basic arithmetic, making it the backbone of 2D platformers and UI systems.[2]
However, AABBs have a fatal flaw: they cannot rotate. When a character leans forward, their AABB must expand awkwardly to encompass the new pose, creating invisible empty space where a player can be hit despite visually dodging the attack.[1][2]
To solve this, developers use Oriented Bounding Boxes (OBBs) or Capsule colliders. An OBB can rotate with the character, offering much higher precision for limbs and weapons, though it requires more complex math—often utilizing the Separating Axis Theorem (SAT) to check for overlaps.[7]
To solve this, developers use Oriented Bounding Boxes (OBBs) or Capsule colliders.
Almost every first-person shooter developed in the last two decades uses capsule colliders for player movement. A capsule—a cylinder with spherical endcaps—is mathematically elegant. The engine only needs to check the distance from a central line segment to the capsule's radius, making it perfect for navigating uneven terrain without snagging on corners.[4][6]
In the hyper-precise world of 2D fighting games, developers separate these shapes into distinct categories. A "hurtbox" is the passive shape that represents the character's vulnerable body, while a "hitbox" is the active shape that deals damage.[5]
This distinction is critical because the two shapes have entirely different lifespans. A hurtbox exists on every frame the character is alive. A hitbox, however, might only exist for three to five frames—roughly 50 to 80 milliseconds—before vanishing.[5]
When a player throws a punch, the engine spawns a hitbox attached to the fist. If that hitbox overlaps the opponent's hurtbox, the engine fires a collision event, triggering damage, hitstun, and particle effects.[3][5]
Tactical shooters introduce another layer of complexity: raycasting. When a player fires a hitscan weapon like a sniper rifle, the game does not spawn a physical bullet. Instead, it casts an invisible mathematical ray from the barrel of the gun directly forward.[1]
The engine then checks if this ray intersects with any enemy capsule colliders along its path. Because raycasting is instantaneous, it creates the crisp, responsive gunplay that defines modern esports, though it requires complex lag compensation to ensure what the shooter sees matches the server's reality.[6]
Fast-moving projectiles introduce a unique physics problem known as "tunneling." If a bullet is moving fast enough, it might exist on one side of a thin wall during Frame 1, and on the other side during Frame 2. Because discrete collision detection only checks for overlaps at specific moments in time, the bullet completely bypasses the wall.[1]
To prevent tunneling, engines use Continuous Collision Detection (CCD). Instead of checking static positions, CCD calculates the time of impact by sweeping the object's shape along its trajectory, finding the exact fraction of a millisecond when the distance between the two bodies reached zero.[7]
Ultimately, collision detection is a masterclass in compromise. Developers must constantly balance the player's demand for pixel-perfect accuracy against the hardware's demand for computational efficiency. The next time you survive a headshot by a millimeter, thank the invisible geometry that decided your fate.[6]
Viewpoints in depth
Engine Architects
Prioritizing computational efficiency and stable frame rates over pixel-perfect physical accuracy.
For the engineers building the underlying physics engines, collision detection is a battle against quadratic scaling. If a game attempts to check every polygon of a character model against every polygon of an environment, the O(n²) complexity will instantly consume the 16.6-millisecond frame budget. Architects rely on spatial partitioning and broad-phase checks—like AABB trees—to rapidly eliminate non-colliding objects before spending CPU cycles on precise narrow-phase math.
Fighting Game Developers
Using distinct hitboxes and hurtboxes as a balancing tool rather than a strict physical simulation.
In the fighting game community, hitboxes are not meant to perfectly match the character's visible art. A sword's active hitbox might extend slightly beyond the blade to make the attack feel more generous, while a character's hurtbox might shrink during a dash to reward evasive timing. By decoupling the physics shapes from the visual mesh, designers can manually tune the 'feel' and fairness of every single frame of animation.
Tactical Shooter Designers
Relying on instantaneous raycasting and capsule colliders to create crisp, responsive gunplay.
Shooter developers face a different challenge: resolving high-speed ballistics across a network. Rather than simulating physical bullets that could tunnel through walls between frames, they use hitscan raycasting. When a player fires, the engine draws an infinite mathematical line and checks which capsule colliders it intersects. This guarantees immediate feedback, though it requires aggressive lag compensation to ensure the server agrees with the shooter's client.
Why this matters
A single pixel of overlap decides million-dollar esports tournaments. Understanding how game engines calculate these invisible collisions reveals why your shots miss and why developers must prioritize computational speed over perfect visual accuracy.
Sources
[1]WikipediaEngine ArchitectsCollision detection
Read on Wikipedia →
[2]LearnOpenGLEngine ArchitectsCollision detection
Read on LearnOpenGL →
[3]Valve Developer CommunityTactical Shooter DesignersHitbox
Read on Valve Developer Community →
[4]Unity DocumentationTactical Shooter DesignersBoxCollider
Read on Unity Documentation →
[5]The Fighting Game GlossaryFighting Game DevelopersHitbox
Read on The Fighting Game Glossary →
[6]Factlen Editorial TeamEngine ArchitectsSynthesis by Factlen editorial team
Read on Factlen Editorial Team →
[7]GitHubEngine Architectsqu3e: A compact, light-weight and fast 3D physics engine in C++
Read on GitHub →
Comments
Every angle. Every day.
Get gaming esports stories with full source coverage and perspective breakdowns delivered to your inbox.

