Collisions
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.
| Type | Description |
|---|---|
ALL | Enable collisions between any kind of rigid-bodies (including between two non-dynamic bodies). |
DEFAULT | The 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_DYNAMIC | Enable collision-detection between a collider attached to a dynamic body and another collider attached to a dynamic body. |
DYNAMIC_FIXED | Enable 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_KINEMATIC | Enable collision-detection between a collider attached to a dynamic body and another collider attached to a kinematic body. |
FIXED_FIXED | Enable 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_FIXED | Enable 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_KINEMATIC | Enable 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
| Prop | What it filters | Contact events? | Contact forces? |
|---|---|---|---|
collisionGroups | Whether contacts are detected at all (narrow-phase) | ✗ skipped | ✗ skipped |
solverGroups | Whether 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.
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"
/>