Function useFilterContactPair

  • Registers a callback to filter contact pairs.

    The callback determines if contact computation should happen between two colliders, and how the constraints solver should behave for these contacts.

    This will only be executed if at least one of the involved colliders contains the ActiveHooks.FILTER_CONTACT_PAIR flag in its active hooks.

    Example

    import { useFilterContactPair } from '@react-three/rapier';
    import { SolverFlags } from '@dimforge/rapier3d-compat';

    useFilterContactPair((collider1, collider2, body1, body2) => {
    // Only process collisions for specific bodies
    if (body1 === myBodyHandle) {
    return SolverFlags.COMPUTE_IMPULSE;
    }
    // Let other hooks or default behavior handle it
    return null;
    });

    Parameters

    • callback: ((collider1: number, collider2: number, body1: number, body2: number) => null | number)

      Function that returns:

      • SolverFlags.COMPUTE_IMPULSE (1) - Process the collision normally (compute impulses and resolve penetration)
      • SolverFlags.EMPTY (0) - Skip computing impulses for this collision pair (colliders pass through each other)
      • null - Skip this hook; let the next registered hook decide, or use Rapier's default behavior if no hook handles it

      When multiple hooks are registered, they are called in order until one returns a non-null value. That value is then passed to Rapier's physics engine.

        • (collider1: number, collider2: number, body1: number, body2: number): null | number
        • Parameters

          • collider1: number
          • collider2: number
          • body1: number
          • body2: number

          Returns null | number

    Returns void

Generated using TypeDoc