Documentation
    Preparing search index...

    Class Collider

    A collision shape attached to a node, belonging to that node's (or an ancestor's) RigidBody (§24).

    const node = new Group();
    node.addComponent(new RigidBody({ type: "dynamic", mass: 1 }));
    const collider = node.addComponent(
    new Collider({ shape: { type: "sphere", radius: 0.5 }, restitution: 0.6 }),
    );

    collider.body; // the RigidBody above
    collider.effectiveFriction; // §25 resolution

    const zone = new Group();
    zone.addComponent(new RigidBody({ type: "static" }));
    const sensor = zone.addComponent(
    new Collider({ shape: { type: "box", halfExtents: extents }, sensor: true }),
    );
    sensor.on("triggerenter", (event) => console.log(event.other));

    One per node (§6a); see the module header for how a body carries several.

    Hierarchy (View Summary)

    Implements

    Index
    • Builds a collider from options, validated against §24, §25, and §85.

      The shape is checked on its own terms (parameters, convexity) and the remaining fields against the dimension the shape implies; the world's dimension is checked later by Collider.validateFor. The offset transform is copied (position and rotation only), so the caller keeps ownership of whatever it passes in.

      Parameters

      Returns Collider

    collisionGroups: number

    Bit set of the groups this collider belongs to (§24).

    collisionMask: number

    Bit set of the groups this collider collides with (§24).

    density?: number

    Mass per unit volume in kg/m³ (§24), or undefined to fall back to §25.

    friction?: number

    Coulomb friction coefficient (§24), or undefined to fall back to §25.

    host: ComponentHost | null

    The node this component is attached to, or null. Written by the ComponentRegistry alone (§6a); never assign it.

    material?: PhysicsMaterial

    Shared surface properties (§25), or undefined. A fallback only: the explicit fields below win where both are set.

    offset: Transform

    Pose of the shape in the body's local frame (§24). Owned by the component and never replaced; only position and rotation are read, because a collider has no scale and no pivot (§37 ColliderDescriptor.offset).

    restitution?: number

    Restitution (§24), or undefined to fall back to §25.

    sensor: boolean

    Whether this collider reports overlaps without exerting forces (§24). A sensor emits "triggerenter" / "triggerexit" instead of collision events (§29).

    The collider's geometry (§24). Held by reference — shapes are plain, shareable data — and re-validated by Collider.validateFor when the collider is registered, so replacing it before registration is free.

    typeName: "collider"

    Component key (plan D2) and §79 serialization name.

    • get body(): RigidBody | undefined

      The body this collider belongs to, or undefined while it has none.

      Resolved on every read: the RigidBody on this collider's own node, else the nearest ancestor's. See the module header for why resolution is lazy and why the ancestor walk is what lets one body carry several colliders.

      The walk needs a scene graph, so it runs only when the host is a @fourjs/scene Node; a bare ComponentRegistry host resolves against itself alone.

      Returns RigidBody | undefined

    • get disposed(): boolean

      Whether Collider.dispose has run. Disposal is terminal (§83): a disposed component refuses world registration with INVALID_APPLICATION_STATE (§89) rather than silently working.

      Returns boolean

    • get effectiveDensity(): number

      The density used to derive mass from this collider (§23, §25) — §25's rule exactly, through resolveDensity: the collider's own density is authoritative, the material's is the fallback, and DEFAULT_DENSITY is the last resort.

      Returns number

    • get effectiveFriction(): number

      The friction a contact with this collider uses (§24, §25): the explicit Collider.friction, else the material's, else DEFAULT_FRICTION.

      Combine it with the other collider's value through combineFriction / combineValues to get the coefficient of a contact (§25, Appendix A).

      Returns number

    • get effectiveRestitution(): number

      The restitution a contact with this collider uses (§24, §25): the explicit Collider.restitution, else the material's, else DEFAULT_RESTITUTION.

      Returns number

    • Drops every listener (§6a, §83). Detaching does not dispose (§6a), so this runs only from an explicit dispose() or ComponentRegistry.disposeAll.

      Returns void

    • Number of live listener registrations across every event type (§83).

      Used by teardown diagnostics — a detached node that still holds listeners pins its subtree until those listeners are removed.

      Returns number

    • Removes every listener, or every listener of one type. Used by teardown paths that must not leave detached nodes retaining listeners (§83).

      Type Parameters

      Parameters

      • Optionaltype: K

      Returns void

    • Collider.body, or a FourError explaining that the collider has no body (§23: every collider belongs to one).

      INVALID_SCENE_GRAPH because the fault is an arrangement of nodes and components, not a bad value. Called by PhysicsWorld at registration (WP-5.3).

      Returns RigidBody

    • The descriptor an adapter would be handed for this collider (§37 createCollider), attached to body.

      friction, restitution, and density are the effective values: §25's fallback chain is resolved here, once, so an adapter receives numbers and never has to re-implement the material rule. The material itself is still passed through for adapters that model §25's optional rolling and spinning friction. The shape and the offset are references to this component's live state; the adapter reads them during createCollider and must not retain them.

      Parameters

      Returns ColliderDescriptor

    • Re-validates this collider against a world of dimension (§21, §24, §85).

      The check a component cannot make on its own: whether its shape belongs to the world it is joining (a "circle" is not a "3d" shape) and whether its offset lies in the plane a "2d" world simulates. Called at registration (WP-5.3); not a per-step path.

      Parameters

      Returns void