Skip to content
BENIBIX Learn

Collision Detection

Development🎮 Game DevelopmentGame Physics

Also known as Collision, Collisions, Collision Checking

How a game finds out that two things are touching.

Think of it like

Think of it like playing tag. The game keeps asking who touched whom.

Example

In Jack's game, a coin vanishes when the player's box overlaps the coin's box.

Why it matters

Nearly every game rule needs it: walls, hits, pickups and floors.

Definition

Collision detection is how a game finds out that two things touch. Each frame, it checks whether their shapes overlap. To keep this fast, games test simple shapes, like boxes and circles, not the detailed drawings. When two shapes overlap, the game reacts, such as taking a life or picking up a coin.

Example code

python
def overlap(a, b):
    return (a.x < b.x + b.w and b.x < a.x + a.w and
            a.y < b.y + b.h and b.y < a.y + a.h)
Two boxes touch when they overlap on both the left-right line and the up-down line.
The right panel: the boxes overlap, so the game counts a collision.

Common mistake

Moving fast things too far each frame. A bullet can skip right over a thin wall.

Key takeaways

  1. 1
    Check each frame. The test runs on every pass of the loop.
  2. 2
    Simple shapes. Boxes and circles are fast to test.
  3. 3
    Then react. The game decides what a touch means.