What is Collision Detection?
Collision detection is a core part of a physics engine. It determines whether two (or more) objects are intersecting (overlapping) or are about to collide, so that the engine can respond — by stopping movement, triggering physics responses, or firing events.
It typically involves two stages:
- Broad phase – quickly checks potential collisions using bounding volumes (e.g. AABB).
- Narrow phase – does precise checks with shapes (like spheres, boxes, polygons, meshes).
What Is “Incorrect” Collision Detection?
“Incorrect” collision detection can mean:
- False positives: Detecting a collision that didn’t actually happen
- False negatives: Missing a collision that did happen
- Tunneling: Fast-moving objects pass through others without detection
- Jittering: Objects constantly flicker or bounce due to rapid contact/resolve cycles
- Sticky surfaces: Objects get stuck or don’t separate correctly after contact
- Overlap without resolution: Colliders pass through each other and stay overlapped
Common Causes of Incorrect Collision Detection
1. High Object Speed (Tunneling)
- If an object moves too far between frames, it may skip past other colliders.
- Fixes:
- Use continuous collision detection (CCD) instead of discrete
- Increase physics update rate (smaller
fixedDeltaTime
) - Use raycasting or sweeps for fast projectiles
2. Low Physics Update Rate
- If your physics timestep is too long (e.g. low FPS), collisions can be missed or jittery.
- Fix:
- Set a smaller fixed time step (
FixedUpdate
in Unity orsubsteps
in Unreal)
- Set a smaller fixed time step (
3. Improper Collider Configuration
- Incorrect shapes, scales, or hierarchy (e.g., colliders not matching visuals)
- Fix:
- Double-check all collider types (box, sphere, mesh, etc.)
- Make sure colliders are properly scaled and aligned with objects
4. Improper Layer or Mask Settings
- In some engines, collision layers or masks control which objects interact.
- Fix:
- Ensure correct collision layers/masks are set to allow proper detection
5. Rigidbodies Missing or Incorrect
- If colliders don’t have appropriate rigidbody components, they may not behave as expected.
- Fix:
- Static objects: collider only
- Dynamic objects: collider + dynamic rigidbody
- Kinematic objects: collider + kinematic rigidbody (for controlled motion)
6. Precision Issues or Floating-Point Errors
- In large worlds or at tiny scales, floating-point precision can cause detection problems.
- Fix:
- Keep simulations near world origin
- Use reasonable object scales (not too small or too big)
7. Mesh Colliders vs. Primitive Colliders
- Mesh colliders can be less accurate and more expensive.
- Fix:
- Use primitive colliders (box, capsule, sphere) where possible
- Use convex meshes for dynamic objects
Debugging & Fixing Tips
- Visualize Colliders: Most engines have a debug view to show colliders in the editor or at runtime.
- Log Collisions: Log collision callbacks to see if/when they’re triggered.
- Raycast or Sweep Test: Manually check expected collisions.
- Sub-Stepping: Some engines support sub-stepping for more accurate results.
Engine-Specific Notes
Unity
Collision Detection Mode
: Set to Continuous or Continuous Dynamic for fast-moving objects.- Use
FixedUpdate
for physics interactions. - Use
Physics.autoSimulation = false
for custom stepping if needed.
Unreal Engine
- Check collision presets and response channels.
- Use CCD (
bUseCCD = true
) for fast objects. - Consider using
Sweep
with movement functions.
Box2D / 2D Engines
- Fast-moving bullets should use raycasts or bullet mode.
- Ensure proper collision filters (category/mask bits).
✅ Best Practices Summary
Problem | Fix |
---|---|
Tunneling | Use continuous collision detection or raycasts |
Missed collisions | Increase physics update rate |
Jittering | Stabilize contact resolution, avoid stacking |
Overlapping | Ensure correct collider types and rigidbody use |
Performance issues | Use simple colliders and layers |