Search The Query
Search

Indie Game Development Guides, Tutorials & Business Insights

  • Home
  • Uncategorized
  • Unity Collision Detection Modes: Stop Your Objects From Passing Through Walls (For Good)
A bullet passes through a wall on the left ("Before - Discrete"), while on the right ("After - CCD") the bullet is stopped by the wall, vividly illustrating Unity Collision Detection Modes in Unity Physics.

Unity Collision Detection Modes: Stop Your Objects From Passing Through Walls (For Good)

You’re testing your game. A bullet fires across the screen — and vanishes straight through a concrete wall. You stare at the Inspector. You check your collider sizes. You rewrite the movement script. Three hours later, the bullet still tunnels through. Sound familiar?

You didn’t have a code bug. You had the wrong Collision Detection Mode.


Key Takeaways Unity collision detection modes

  • Unity’s default Discrete mode is fast but can miss collisions on fast-moving objects between physics frames.
  • The physics “tunneling” problem is caused by objects moving so fast they skip over a collider entirely between updates.
  • There are four modes: Discrete, Continuous, Continuous Dynamic, and Continuous Speculative — each with different cost/accuracy trade-offs.
  • Unity’s own official docs recommend starting with Discrete and only escalating to Continuous Speculative when tunneling is observed.unity3d
  • A single Inspector setting change can resolve most ghost-collision bugs before you spend hours debugging.unity3d

What Is the Tunneling Problem?

Physics in Unity runs on a fixed timestep — by default, every 0.02 seconds. Between each tick, a Rigidbody moves from point A to point B. If that object is moving very fast, point B might be on the other side of a wall. Unity’s default behavior never checks what happened between A and B. The object effectively teleports past the collision.unity.huh

This phenomenon is called physics tunneling, and it’s one of the most deceptively maddening bugs in real-time game development. The fix is not in your script. It’s in the Collision Detection dropdown inside the Rigidbody component.


The Four Collision Detection Modes Explained

1. Discrete (Default)

Discrete checks for collisions only at discrete time points — once per physics step. It’s the cheapest mode and the right choice for the majority of your game objects: characters, crates, enemies, doors. No swept calculations. No predictive math. Just fast.unity3d

The catch: any object moving faster than its own width per physics frame can tunnel. For a bullet traveling at 100 m/s with a FixedTimestep of 0.02s, that’s 2 meters per frame — easily skipping over a thin wall entirely.

Use it for: Player characters, NPCs, props, most gameplay objects that move at normal speeds.


2. Continuous

Continuous mode performs a sweep-based Continuous Collision Detection (CCD) between the object’s previous position and its new position, but only against static colliders (GameObjects without a Rigidbody). Think walls, floors, terrain — anything that doesn’t move.unity3d

It does not prevent tunneling against other moving Rigidbodies unless those objects are set to Continuous Dynamic. It costs more CPU than Discrete, so don’t apply it blindly.docs.unity3d

Use it for: Fast vehicles hitting level geometry, racing games where cars must not pass through guardrails or track boundaries.


3. Continuous Dynamic

This is the heavy artillery. Continuous Dynamic sweeps against both static colliders and other Rigidbodies that are also set to Continuous or Continuous Dynamic. It uses the highest CPU cost of all modes, and that cost scales with the number of possible interactions.unity3d

Unity’s own documentation calls it a “last resort” — use it only for critical objects that absolutely cannot tunnel through other fast-moving dynamic objects.unity3d

Use it for: Bullets, rockets, fast projectiles in physics-heavy shooters — especially when they must reliably collide with other moving physics objects.


4. Continuous Speculative

The newest and often the best general-purpose CCD option. Instead of sweeping, Continuous Speculative expands the object’s bounding volume based on its velocity and predicts potential future collisions, then resolves them preemptively.unity3d

It’s typically more performant than Continuous modes while offering comparable (and sometimes better) tunneling prevention. It handles rotational collisions far better than sweep-based methods, which completely ignore angular velocity. One important caveat: it can occasionally produce “ghost contacts” — registering a collision that never quite happened — on very fast-spinning objects.unity3d+2

Use it for: Extremely fast objects, kinematic Rigidbodies, objects with complex or unpredictable motion, VR melee weapons.


Quick-Reference Mode Selector

Comparison chart illustrating four Unity collision detection modes—discrete, continuous, continuous dynamic, and continuous speculative—ranked on a spectrum from performance to accuracy.
Comparison chart illustrating four Unity collision detection modes—discrete, continuous, continuous dynamic, and continuous speculative—ranked on a spectrum from performance to accuracy.
ScenarioRecommended ModeWhy
Player character, NPCs, propsDiscreteBest performance; no tunneling risk at normal speeds unity3d
Fast car hitting static wallsContinuousSweeps against static geometry only unity3d
Bullet vs. moving enemy RigidbodyContinuous DynamicSweeps against both static + dynamic objects unity3d
Extreme-speed object, rotating projectileContinuous SpeculativePredictive; handles rotation; best balance unity3d+1

Real Stories From Developers

“I Rewrote My Entire Bullet Script for Nothing”

A developer on a 2D shooter spent two days rewriting their projectile system after bullets clipped through enemies. The root issue? All enemies were Rigidbodies on Discrete, and bullets were on Continuous — which only sweeps against static colliders. Switching the bullets to Continuous Dynamic resolved it in under a minute.discussions.unity

The VR Sword That Kept Phasing Through Knights

A Unity VR melee combat developer discovered that thin, elongated box colliders on sword blades caused the PhysX engine to “take shortcuts” in its math — essentially treating the long skinny shape as negligible. The fix was two-fold: replace the box collider with a custom convex mesh collider for the blade, and apply Continuous Speculative to the sword’s Rigidbody. The tunneling vanished, and the physics response was significantly smoother.youtube

The Hyperfast Racing Game

One developer building a sci-fi racer reported their ship reaching ~2000 km/h in Unity’s default units — a scenario where no single collision detection mode was completely satisfying. Their solution was a hybrid: Continuous Speculative combined with reducing the FixedTimestep interval from 0.02s to 0.008333s (120Hz), effectively giving physics more opportunities to catch collisions before an object crosses an entire wall.discussions.unity+1


How to Change Collision Detection Mode (Step-by-Step)

  1. Select the GameObject that needs fixing in the Hierarchy.
  2. In the Inspector, find the Rigidbody component.
  3. Locate the Collision Detection dropdown.
  4. Change from Discrete to the appropriate mode.
  5. Hit Play and test. Escalate only if tunneling persists.

You can also change it in code at runtime:

// Switch to Continuous Speculative at runtime
GetComponent<Rigidbody>().collisionDetectionMode = 
    CollisionDetectionMode.ContinuousSpeculative;

Unity’s API reference confirms ContinuousSpeculative can even be applied to Kinematic Rigidbodies — something the other CCD modes do not support.docs.unity3d


Advanced Tips & Common Pitfalls

Don’t apply CCD to everything. The performance cost compounds with the number of active CCD objects. Reserve Continuous and Continuous Dynamic for the 2–3 critical objects per scene that actually need it.unity3d

Thin colliders are enemy #1. Any collider thinner than the distance an object travels in one physics frame is a tunneling candidate regardless of mode — especially with sweep-based CCD, which can miss very thin geometry at certain angles. Make your walls at least as thick as the fastest object’s per-frame travel distance.unity3d

Continuous ignores rotation. Sweep-based CCD calculates a straight linear path. A fast-spinning object with Continuous or Continuous Dynamic can still tunnel if its angular velocity is the main cause of movement. Use Continuous Speculative for spinning objects.unity3d

Lower your FixedTimestep when all else fails. Reducing Time.fixedDeltaTime (e.g., from 0.02 to 0.01) doubles the frequency of physics updates, which helps catch collisions even in Discrete mode — at the cost of doubled physics CPU load.discussions.unity

Dynamic switching is valid. Some developers write scripts that switch collision mode based on object velocity — using Discrete at slow speeds and escalating to Continuous Speculative when above a threshold. This is a legitimate and efficient technique for highly variable-speed objects.discussions.unity



The Decision Tree: Which Mode Should You Pick?

Follow this flowchart logic before touching anything else:

  1. Does the object move slowly? → Use Discrete. Done.
  2. Does it move fast and hit static walls/geometry only? → Use Continuous.
  3. Does it move fast AND collide with other moving Rigidbodies? → Use Continuous Dynamic.
  4. Is it extremely fast, rotating, or unpredictable in motion? → Use Continuous Speculative.
  5. Still tunneling after step 4? → Combine Continuous Speculative with a reduced FixedTimestep and review collider thickness.discussions.unity+1

The official Unity optimization guide makes this hierarchy explicit: start at Discrete, and only escalate when you observe actual tunneling. Never pre-emptively apply CCD to every object.unity3d


Quick Tip

If an object is passing through colliders, try a higher Collision Detection Mode before spending hours debugging your code.unity3d

A single dropdown in the Inspector has solved bugs that developers have blamed on scripts, collider meshes, frame rates, and even “Unity being broken.” Check it first. It takes five seconds.


Have you hit the tunneling problem in a project? Drop the scenario in the comments — the object type, speed, and which mode finally fixed it. Every edge case is different, and the community learns from real data.

Conclusion on Unity collision detection modes

Balancing physical accuracy with CPU performance is a core skill in game optimization. By mastering Unity collision detection modes, you ensure your game feels solid, responsive, and professional. Stick to Discrete by default, and save the Continuous modes for the objects that truly need them.