You can customize how Rapier handles collisions and intersections by providing custom callback functions for filter_contact_pair and filter_intersection_pair. These hooks are passed to the physics engine to decide whether certain interactions should be ignored or how they should be flagged.
filter_intersection_pair
This hook is used to determine if two colliders should trigger an intersection event.
- Arguments: Receives the handles for
collider1 and collider2, and optionally the handles for rigid_body1 and rigid_body2 (if the colliders are attached to bodies). - Return Value: A boolean. Return
true to allow the intersection, or false to ignore it.
filter_contact_pair
This hook is used to modify the solver flags for a contact pair, allowing you to change how the physics engine resolves the collision.
- Arguments: Receives the handles for
collider1 and collider2, and optionally the handles for rigid_body1 and rigid_body2. - Return Value: A number representing
SolverFlags. This value is treated as a bitmask to set specific solver behaviors.
Note: The modify_solver_contacts interface is currently a placeholder in the JS bindings and does not yet support full contact modification.
// Example of what the JS callback signatures look like conceptually:
// filter_intersection_pair(colliderHandle1, colliderHandle2, rbHandle1?, rbHandle2?): boolean
const myIntersectionFilter = (c1, c2, rb1, rb2) => {
return c1 !== c2; // Simple example logic
};
// filter_contact_pair(colliderHandle1, colliderHandle2, rbHandle1?, rbHandle2?): number (SolverFlags)
const myContactFilter = (c1, c2, rb1, rb2) => {
return 0; // Return SolverFlags bits
};