Skip to main content

collider_active_hooks

Physics hooks are user-defined callbacks used to filter-out some contact pairs, or modify contacts, based on arbitrary user code. In order to enable a physics hook for a pair of colliders, at least one of the involved colliders must have the corresponding hook set as active. A hook is activated for a collider by setting its corresponding active hooks bit to 1:

  • Setting the ActiveHooks::FILTER_CONTACT_PAIRActiveHooks.FILTER_CONTACT_PAIRR3_FILTER_CONTACT_PAIRSActiveHooks.FILTER_CONTACT_PAIR bit to 1 enables the manual filtering of all the contact pairs involving the collider.
  • Setting the ActiveHooks::FILTER_INTERSECTION_PAIRActiveHooks.FILTER_INTERSECTION_PAIRR3_FILTER_INTERSECTION_PAIR ActiveHooks.FILTER_INTERSECTION_PAIR bit to 1 enables the manual filtering of all the intersection pairs involving the collider. - Setting the ActiveHooks::MODIFY_SOLVER_CONTACTS bit to 1 enables the manual contact modification for all the contact manifolds involving the collider. - Setting the R3_MODIFY_SOLVER_CONTACTS bit to 1 enables the manual contact modification for all the contact manifolds involving the collider. - Setting the ActiveHooks.MODIFY_SOLVER_CONTACTS bit to 1 enables the manual contact modification for all the contact manifolds involving the collider.

The active hooks of a collider can be set when the collider is created or after its creation (the callbacks themselves are given to r3Step as a R3PhysicsHooks, see physics hooks) (the callbacks themselves are given by the object assigned to the physics_hooks property of the PhysicsWorld, see physics hooks):

/* Set the active hooks when the collider is created. */
let collider = ColliderBuilder::ball(0.5)
.active_hooks(ActiveHooks::FILTER_CONTACT_PAIRS | ActiveHooks::MODIFY_SOLVER_CONTACTS)
.build();
/* Set the active hooks after the collider creation. */
let collider = &mut world.colliders[collider_handle];
collider
.set_active_hooks(ActiveHooks::FILTER_CONTACT_PAIRS | ActiveHooks::MODIFY_SOLVER_CONTACTS);
assert!(collider
.active_hooks()
.contains(ActiveHooks::FILTER_CONTACT_PAIRS));
assert!(collider
.active_hooks()
.contains(ActiveHooks::MODIFY_SOLVER_CONTACTS));
/* Set the active hooks when the collider is created. */
commands
.spawn(Collider::ball(0.5))
.insert(ActiveHooks::FILTER_CONTACT_PAIRS | ActiveHooks::MODIFY_SOLVER_CONTACTS);
/* Set the active hooks inside of a system. */
fn modify_collider_active_hooks(mut active_hooks: Query<&mut ActiveHooks>) {
for mut active_hooks in active_hooks.iter_mut() {
*active_hooks = ActiveHooks::FILTER_CONTACT_PAIRS | ActiveHooks::MODIFY_SOLVER_CONTACTS;
}
}
/* Set the active hooks when the collider is created. */
let colliderDesc = RAPIER.ColliderDesc.ball(0.5)
.setActiveHooks(RAPIER.ActiveHooks.FILTER_CONTACT_PAIRS);
let collider = world.createCollider(colliderDesc);
/* Set the active hooks after the collider creation. */
collider.setActiveHooks(RAPIER.ActiveHooks.FILTER_CONTACT_PAIRS);
/* Set the active hooks when the collider is created. */
R2ColliderDesc collider = r2BallColliderDesc(0.5);
collider.activeHooks = R2_FILTER_CONTACT_PAIRS | R2_MODIFY_SOLVER_CONTACTS;
/* Set the active hooks after the collider creation. */
r2Collider_SetActiveHooks(collider_handle, R2_FILTER_CONTACT_PAIRS | R2_MODIFY_SOLVER_CONTACTS);
assert(r2Collider_ActiveHooks(collider_handle) & R2_FILTER_CONTACT_PAIRS);
assert(r2Collider_ActiveHooks(collider_handle) & R2_MODIFY_SOLVER_CONTACTS);
# Set the active hooks when the collider is created.
collider = (
rp.Collider.ball(0.5)
.active_hooks(rp.ActiveHooks.FILTER_CONTACT_PAIRS | rp.ActiveHooks.MODIFY_SOLVER_CONTACTS)
.build()
)
# Set the active hooks after the collider creation.
collider = world.colliders[collider_handle]
collider.active_hooks = rp.ActiveHooks.FILTER_CONTACT_PAIRS | rp.ActiveHooks.MODIFY_SOLVER_CONTACTS
assert collider.active_hooks.contains(rp.ActiveHooks.FILTER_CONTACT_PAIRS)
assert collider.active_hooks.contains(rp.ActiveHooks.MODIFY_SOLVER_CONTACTS)