# Use the simplest collision test that fits the shape

> Pick a collision representation that fits your game, reduce unnecessary pair checks, and diagnose objects passing through obstacles.

- URL: https://oneshotgems.ai/topics/game-collision-detection
- Category: For game developers
- Type: Guide
- Updated: October 5, 2026

Collision detection asks whether game objects overlap or cross paths. The best first representation is usually simpler than the artwork: rectangles for grid cells and platforms, circles for round actors, or a small collection of shapes for an irregular obstacle. Begin with a clear question—touching, entering, or crossing—and choose a test that answers it consistently. Pixel-perfect checks add complexity and are rarely needed for a game whose rules are already approximate.

## Match the test to the rule

For axis-aligned rectangles, compare each object's left, right, top, and bottom extents; overlap occurs when the intervals intersect on both axes. For circles, compare center distance with the sum of radii. A grid game can avoid geometry entirely by checking whether two actors claim the same cell.

Make a tiny diagnostic scene with two colored shapes and display their chosen hit regions. Move each pair through edge contact, partial overlap, and a near miss. Decide whether touching edges counts as collision and encode that convention once so movement and scoring do not disagree.

## Avoid missing fast crossings

A fast object can be on one side of a thin wall on one update and on the other side on the next. Smaller fixed simulation steps can help, but are not the only answer: test a swept segment or expanded target when the movement range is large relative to the obstacle thickness.

With many objects, first reject pairs that cannot be near each other using a coarse grid or spatial buckets, then run detailed tests on the candidates. Measure before adding that structure; for a few dozen entities, straightforward pair checks may be easier to maintain and perfectly adequate.

## Questions

**Do hitboxes need to match sprite outlines?** Usually not. A slightly forgiving rectangle or circle can make controls feel fairer. Show hitboxes during development and tune them against the intended rule and player expectation.

**Can Canvas tell me whether two sprites collide?** Canvas provides path tests such as isPointInPath() for checking a point against a drawn path, but it does not define general game-object collision rules. Keep simulation geometry explicit and independent of drawing.

## Follow your curiosity

- [Use Delta Time Without Jumpy Motion](https://oneshotgems.ai/topics/delta-time-in-games): Apply elapsed time to game motion, choose a safe catch-up policy, and test movement at different refresh rates and after stalls.
- [Build a Reliable Browser Game Loop](https://oneshotgems.ai/topics/browser-game-loop): Structure browser game updates and drawing around animation frames without tying simulation speed to a player’s display refresh rate.
- [Use a Fixed Timestep for Game Physics](https://oneshotgems.ai/topics/fixed-timestep-game-physics): Separate physics updates from rendering with a fixed simulation step, bounded catch-up work and tests for stalls and collisions.

## Further reading

- [MDN: Canvas isPointInPath()](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/isPointInPath)

---
Canonical page: https://oneshotgems.ai/topics/game-collision-detection
