How Continuous Collision Detection Prevents Tunneling
In physics-driven game development, continuous collision detection (CCD) algorithms prevent high-velocity projectiles from passing through obstacles—a glitch known as tunneling—by computing collisions continuously over time rather than checking overlaps at static intervals. Standard discrete collision engines evaluate object positions at fixed simulation steps, allowing ultra-fast objects to skip completely past thin geometry within a single frame. CCD resolves this by analyzing the entire volume of space an object sweeps through during a time step, calculating the exact time of impact, and resolving the contact before the projectile can breach the surface.
The Tunneling Problem in Discrete Physics
Most game physics engines operate on fixed time steps, evaluating scenes at predetermined intervals (such as 60Hz or 120Hz). In a discrete detection model:
- The engine calculates an object's position at time \(t\).
- It applies forces and velocities to calculate the new position at time \(t + \Delta t\).
- It checks whether the projectile's collider intersects any other colliders at that final position.
If a projectile travels faster than the thickness of a target wall within the span of \(\Delta t\), its position jumps from one side of the wall to the other without ever occupying the space inside the wall. Because no overlap exists at either \(t\) or \(t + \Delta t\), the engine registers no collision, causing the projectile to phase straight through the barrier.
Swept Volumes and Shape Casting
The most common implementation of CCD uses swept volume tests. Instead of treating the projectile as a static shape at the beginning and end of a frame, the engine extrudes the projectile's bounding volume along its motion vector:
- Raycasting: For zero-thickness or negligible-radius projectiles (such as small bullets), the physics engine casts an infinite or length-limited ray from the origin point to the target point across \(\Delta t\).
- Shape Casting (Swept Spheres/Capsules): For projectiles with noticeable physical dimensions, the engine sweeps a 3D primitive (like a sphere or box) along the trajectory, creating an extruded volume (such as a capsule for a sphere).
If this swept geometry intersects an environmental collider, the engine identifies that an impact occurred, marks the exact intersection point, and retrieves the surface normal for response calculations.
Time of Impact (TOI) and Conservative Advancement
For complex, arbitrary convex shapes where sweeping is computationally expensive, physics engines use predictive algorithms based on Conservative Advancement and the Gilbert-Johnson-Keerthi (GJK) distance algorithm.
Conservative advancement works by calculating the minimum separating distance between the projectile and an obstacle at the start of the time step. Knowing the maximum relative velocity of the projectile, the engine computes a safe time interval during which a collision is mathematically impossible. The simulation advances by that safe fraction of time and recalculates the distance. This process iterates until the separation falls below a tiny threshold (indicating an impact) or the end of the physics frame is reached. The moment contact occurs is designated as the Time of Impact (TOI).
Speculative Contacts
Another technique employed by modern engines is speculative collision detection. Instead of generating continuous sweeps or advancing time iteratively, speculative contact algorithms expand the broad-phase bounding boxes of moving objects in the direction of their velocity.
When a potential contact is identified ahead of the projectile, the engine establishes a temporary contact constraint with a distance limit. If the projectile moves toward the surface during the velocity integration step, the constraint removes sufficient velocity to prevent penetration, ensuring the projectile stops precisely at the surface during the discrete step without requiring deep geometric sweeps.
Physics Resolution and Optimization
Once CCD detects a collision along the path, the physics pipeline stops the projectile at the calculated TOI, places it at the exact point of surface contact, and adjusts its velocity based on physical properties such as restitution (bouncing) or friction. Any remaining simulation time (\(\Delta t - \text{TOI}\)) is then integrated from the point of impact.
Because sweeping geometries and iterative root-finding algorithms require significantly more processing power than discrete overlap checks, developers apply CCD selectively. Game engines typically restrict continuous detection to small, high-speed objects like artillery, rockets, and fast-moving dynamic debris, while keeping the rest of the game world on discrete detection to preserve computational performance.