Skip to main content

collider_active_events

Event handlers are user-defined callbacks used to be notified when two colliders start/stop touching. By default no collision event is generated by the narrow-phase. In order to enable a collision event for a pair of colliders, at least one of the involved colliders must have the corresponding event set as active. An event is activated for a collider by setting its corresponding active events bit to 1:

  • Setting the ActiveEvents::COLLISION_EVENTSActiveEvents.COLLISION_EVENTS bit to 1 enables the collision events involving the collider.

The active events of a collider can be set when the collider is created or after its creation:

/* Set the active events when the collider is created. */
let collider = ColliderBuilder::ball(0.5)
.active_events(ActiveEvents::COLLISION_EVENTS)
.build();
/* Set the active events after the collider creation. */
let collider = collider_set.get_mut(collider_handle).unwrap();
collider.set_active_events(ActiveEvents::COLLISION_EVENTS);
assert!(collider
.active_events()
.contains(ActiveEvents::COLLISION_EVENTS));
/* Set the active events when the collider is created. */
commands
.spawn(Collider::ball(0.5))
.insert(ActiveEvents::COLLISION_EVENTS);
/* Set the active events inside of a system. */
fn modify_collider_active_events(mut active_events: Query<&mut ActiveEvents>) {
for mut active_events in active_events.iter_mut() {
*active_events = ActiveEvents::COLLISION_EVENTS;
}
}
/* Set the active events when the collider is created. */
let colliderDesc = RAPIER.ColliderDesc.ball(0.5)
.setActiveEvents(RAPIER.ActiveEvents.COLLISION_EVENTS);
let collider = world.createCollider(colliderDesc);
/* Set the active events after the collider creation. */
collider.setActiveEvents(RAPIER.ActiveEvents.COLLISION_EVENTS);