Rapier logo

Collisions

Detect and respond to collision events between rigid bodies using the activeCollision prop and collision-enter / collision-exit event listeners.

To start receiving collisions events, first you need to set the active-collision prop to our RigidBody (this set all our automatic colliders). Then you can start listening for events in @collision-enter and/or @collision-exit.

<RigidBody activeCollision @collision-enter="onCollisionEnter" @collision-exit="onCollisionExit">
  <TresMesh>
    <TresTorusGeometry />
    <TresMeshNormalMaterial />
  </TresMesh>
</RigidBody>

enableCcd

You can set continuous collision detection for fast moving object, passing as a prop enableCcd.

<RigidBody activeCollision enableCcd @collision-enter="onCollisionEnter" @collision-exit="onCollisionExit">
  <TresMesh>
    <TresTorusGeometry />
    <TresMeshNormalMaterial />
  </TresMesh>
</RigidBody>

activeCollisionTypes

You can select between the following props the type of collision that fit best your needs.

TypeDescription
ALLEnable collisions between any kind of rigid-bodies (including between two non-dynamic bodies).
DEFAULTThe default active collision types, enabling collisions between a dynamic body and another body of any type, but not enabling collisions between two non-dynamic bodies.
DYNAMIC_DYNAMICEnable collision-detection between a collider attached to a dynamic body and another collider attached to a dynamic body.
DYNAMIC_FIXEDEnable collision-detection between a collider attached to a dynamic body and another collider attached to a fixed body (or not attached to any body).
DYNAMIC_KINEMATICEnable collision-detection between a collider attached to a dynamic body and another collider attached to a kinematic body.
FIXED_FIXEDEnable collision-detection between a collider attached to a fixed body (or not attached to any body) and another collider attached to a fixed body (or not attached to any body).
KINEMATIC_FIXEDEnable collision-detection between a collider attached to a kinematic body and another collider attached to a fixed body (or not attached to any body).
KINEMATIC_KINEMATICEnable collision-detection between a collider attached to a kinematic body and another collider attached to a kinematic body.
<RigidBody activeCollision activeCollisionTypes="ALL" @collision-enter="onCollisionEnter" @collision-exit="onCollisionExit">
  <TresMesh>
    <TresTorusGeometry />
    <TresMeshNormalMaterial />
  </TresMesh>
</RigidBody>

Collision groups and solver groups

collisionGroups

For more complex scenes you can select how collider interact with each other using collisionsGroups

<RigidBody activeCollision :collisionGroups="0x000D0004" @collision-enter="onCollisionEnter" @collision-exit="onCollisionExit">
  <TresMesh>
    <TresTorusGeometry />
    <TresMeshNormalMaterial />
  </TresMesh>
</RigidBody>

solverGroups

solverGroups works with the same bitmask format as collisionGroups, but controls a different step in the physics pipeline:

<RigidBody activeCollision :solverGroups="0x000D0004" @collision-enter="onCollisionEnter" @collision-exit="onCollisionExit">
  <TresMesh>
    <TresTorusGeometry />
    <TresMeshNormalMaterial />
  </TresMesh>
</RigidBody>

collisionGroups vs solverGroups

PropWhat it filtersContact events?Contact forces?
collisionGroupsWhether contacts are detected at all (narrow-phase)✗ skipped✗ skipped
solverGroupsWhether contact forces are applied (after narrow-phase)✓ still fired✗ skipped

Use collisionGroups when you want two colliders to completely ignore each other — it's more efficient because it skips both contact detection and force computation.

Use solverGroups when you still want collision events to fire (e.g. to detect a hit) but don't want physics forces applied — for example, to implement your own custom force response.

For a complete explanation check Collision groups and solver groups

Custom colliders

If you want to detect collisions on custom colliders is the same methodology but applied to the custom collider, for example

<BallCollider
  :args="[1, 1, 1]"
  activeCollision
  @collision-enter="onCollisionEnter"
/>

Events

collision-enter
(payload: { source: SourceTarget, target: SourceTarget }) => void
Triggered when a collider starts colliding with another collider.
collision-exit
(payload: { source: SourceTarget, target: SourceTarget }) => void
Triggered when a collider stops colliding with another collider.