Skip to main content

Continuous Collision Detection

Fast-moving projectiles like bullets are key part of many games, but pose a particular challenge for physics engines.

As the physics engine only checks for collisions once per simulation step, a fast-moving projectile might move so far in a single step that by the time the physics engine checks for collisions, it has already passed through to the other side of a wall. The physics engine misses the collision, and the projectile appears to have "tunneled" through the wall without colliding with it.

The fix for it is to enable continuous collision detection.

Enabling Continuous Collision Detection

Setting intercept=true on a PolygonCollider will enable continuous collision checks between that collider and every other collider.

You can also limit continuous collision checks to particular categories, for example intercept=Category:Wall to only check for collisions against colliders in the Wall category. This reduces the amount of continuous collision checks that need to be performed, which can improve performance.

How It Works

When continuous collision detection is enabled for a collider, the physics engine will sweep that collider along its path during the simulation step to check for collisions. This is computationally expensive, so it is not enabled by default for all colliders, but it can be enabled for specific colliders that need it.

The physics engine will then substep the simulation to the time of collision, resolve the collision, and then continue the simulation for the remaining time in the step.

Performance Impact

Besides the additional sweep tests that need to be performed, continuous collision detection also requires substepping. The entire world must be substepped to the time of collision, not just the colliders involved in the collision, which is another reason why continuous collision detection is computationally expensive.

info

Unfortunately, creating an index to not only find the colliders that are involved in the collision, but to also move away the colliders that should not be involved, takes more time than just substepping the entire world, which is why substepping the entire world is the approach that Easel takes.

To maximize performance, only enable continuous collision detection when necessary.