# Collision Detection

> How a game finds out that two things are touching.

**Field:** Software Development  
**Category:** Game Development  
**Also known as:** Collision, Collisions, Collision Checking

## Think of it like

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

## 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

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

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Hitbox](https://learn.benibix.com/term/development/hitbox)
- [Physics Engine](https://learn.benibix.com/term/development/physics-engine)
- [Game Loop](https://learn.benibix.com/term/development/game-loop)
- [Tilemap](https://learn.benibix.com/term/development/tilemap)

![Two panels. On the left, Apart, no collision: a large circle and a small circle, each inside a dashed box, far from each other, with a note that the dashed boxes are hitboxes. On the right, Overlap, collision, lit up: the two dashed boxes overlap in a shaded strip, and an arrow leads to lose a life. A note says a physics engine then decides how the two things bounce, slide or stop.](https://learn.benibix.com/diagrams/dev2-collision.svg)

---

Source: https://learn.benibix.com/term/development/collision-detection
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
