Skip to main content

rigid_body_ccd

Continuous Collision Detection (CCD) is used to make sure that fast-moving objects don't miss any contacts (a problem usually called tunneling). This is done by looking for collisions along the shapes motion: a rigid-body that moved fast during the timestep casts its colliders from their previous position to their new one, and its position is clamped to the first impact found this way. Its velocities are left untouched and the solver is responsible for preventing penetrations. Since the trajectory is clamped to some intermediate location along its path this technique is commonly called motion clamping.

Rapier applies CCD in two ways:

  • Every fast-moving dynamic rigid-body is swept against the fixed colliders and the soft-bodies of the scene. This is automatic and doesn't need to be enabled: this prevents a falling crate from going through the floor, or a projectile from going through a wall, etc. Note however that this is not enabled fol dynamic rigid-bodies with mesh-like shapes (triangle meshes, polylines, heightfields) as that would be too computationally expensive.
  • A dynamic rigid-body with CCD enabled (aka. a bullet) is swept against the kinematic and dynamic bodies as well. This is more expensive, therefore it is disabled by default and should be reserved to the objects that must not tunnel through moving obstacles. Note that two CCD-enabled objects might still tunel since the CCD resolution does currently not take both continuous motions into account simultaneously.
info

CCD takes action only if the rigid-body is moving fast relative to another collider. Therefore it is useless to enable it on fixed rigid-bodies and on rigid-bodies that are expected to move slowly.

The CCD feature, including the automatic sweeping of the fast dynamic bodies, can be fully disabled by setting the maximum number of CCD substeps to zero in the IntegrationParameters (the PhysicsWorld.integration_parameters.max_ccd_substeps field, whose default is 1). Larger values let a body resolve several successive impacts within a single timestep, at the cost of additional sweeps.

Per-object CCD can be enabled when creating a rigid-body or after its creation:

# Enable CCD when the rigid-body is created.
rigid_body = rp.RigidBody.dynamic().ccd_enabled(True).build()
# Enable CCD after the rigid-body creation.
rigid_body = world.rigid_bodies[rigid_body_handle]
rigid_body.ccd_enabled = True
assert rigid_body.ccd_enabled