14 · Physics & collisions · 2D and 3D

Spatial partitioning

Only test things that are near each other.

Checking every object against every other object costs n squared: 500 bullets means about 125,000 checks a frame. Dropping everything into grid cells (or a quadtree, or a BVH) and only checking neighbours cuts that to a few thousand, which is how games manage crowds, bullets and particles.

G grid on/off↑↓ more or fewer objectsUse the buttons

Try this: Raise the object count with the grid off and watch the checks explode. Turn the grid on with G.

Pair checks per frame 0Collisions 0

Same collisions found either way; only the work changes.

Prompt bit

Works for 2D or 3D in any engine (Unity, Unreal, Godot, web). Paste the short one for a quick fix, or the detailed one when you want it done properly.

Add a uniform grid broadphase: put each object in cells sized about twice its radius, test only pairs in the same or neighbouring cells, rebuild the grid every 0.016 s physics step, and insert objects bigger than a cell into every cell they overlap.

44 words · one sentence to paste as is

Where it's used

Common mistakes

Cells far too small or far too big (both lose the benefit), forgetting big objects that span several cells, testing each pair twice, and rebuilding complex trees every frame when a grid would do.

Writing this with an AI assistant? See our best AI coding assistants for game developers.

Missing a concept? Request one.

Related concepts

New concepts, in your inbox.

One short email when we add new concepts, plus our weekly roundup of AI tools for game devs. Unsubscribe any time.