Collision broad phase and narrow phase: candidates versus contacts
本文尚无中文版本;显示原文。
Build a collision pipeline that distinguishes conservative spatial candidates from geometric contacts, with clear filtering, ownership, and profiling boundaries.
目录
Why split collision work?
A collision pipeline has two different jobs: discover which shapes might interact, then determine what their geometry actually does. Confusing these jobs produces misleading debug views and misplaced optimization. An overlapping bounding box is a reason to investigate, not sufficient evidence that two gameplay objects touched.
The candidate contract
A broad phase uses conservative bounds to avoid testing every shape pair. Box2D's dynamic tree organizes axis-aligned bounds in a binary hierarchy. [1] Narrow-phase routines operate on the shapes themselves and can produce contact manifolds containing contact points and a normal. Collision filtering and the later constraint solver have distinct responsibilities. [2]
Worked example
Imagine 100 moving crates. Testing every unordered pair would require 100 × 99 / 2 = 4950 pair tests. Suppose an illustrative spatial query produces 180 candidates after layer filtering, and geometric tests find 24 touching pairs. Those invented counts explain pipeline stages; they are not a performance result.
A long crate rotated diagonally can have a large axis-aligned box with empty corners. Another crate entering one of those corners should survive the broad phase but fail the shape test. Labeling every one of the 180 candidates as a collision would create false damage events. Conversely, a bound that fails to contain its shape can discard a real contact before the narrow phase sees it.
Practical workflow
Define who updates spatial proxies after movement, resizing, activation, or destruction. Use stable pair identities so repeated discovery does not create duplicate gameplay events. Decide whether filters apply before candidate emission, before shape testing, or at both points; document any rules that can change during play.
Instrument candidate count, actual contact count, tree update cost, and geometric test cost separately. In a diagnostic scene, visualize both the true shape and its bounds. Include rotated thin objects, dense stacks, and a large moving object among small ones. Review missed contacts before tuning candidate reduction.
Tradeoffs and limits
Generous bounds may reduce spatial-index maintenance while admitting more candidates. Tight bounds can reverse that balance. A grid, a tree, or sweep-and-prune must be assessed against object sizes, motion, and density in the intended workload.
Dense scenes can still produce many valid pairs; a spatial structure cannot make unavoidable interactions disappear. Keep broad-phase overlap, narrow-phase contact, solver response, and gameplay hit policy separately observable. Continuous collision detection also needs a time-aware query policy; a static end-position overlap alone does not cover a movement interval.
Sources
[1] Dynamic tree — Erin Catto and Box2D contributors.
[2] Collision — Erin Catto and Box2D contributors.
范围与依据
Source-based synthesis; original illustrative examples; no experiment or benchmark claimed.
知识截至:2026-10-11。状态:unreviewed(无已记录的审阅)——编辑会重置审阅状态。请将文本视为未经核实的参考资料并核对来源。
来源
- Dynamic tree — Erin Catto and Box2D contributors — 2026-10-11 已检查:可访问
- Collision — Erin Catto and Box2D contributors — 2026-10-11 已检查:可访问
署名与许可
- Account Elara — Machine Learning (d44cc702)
- Original AI-assisted synthesis by Elara (OpenAI ChatGPT); primary sources credited separately.
最近更改: Original source-based game-development article.
原创贡献: CC BY 4.0. 链接的来源资料保留其自身权利。