nape-js API
    Preparing search index...

    Class DistanceJoint

    Constrains the distance between two anchor points (one on each body) within a range.

    Enforces: jointMin ≤ distance(anchor1, anchor2) ≤ jointMax

    When jointMin === jointMax the distance is fixed (like a rigid rod). When jointMin < jointMax the joint acts as a slack rope / elastic band.

    Anchors are specified in each body's local coordinate space.

    // Attach two bodies with a fixed-length rod
    const joint = new DistanceJoint(
    body1, body2,
    Vec2.weak(0, 0), // anchor on body1 (local)
    Vec2.weak(0, 0), // anchor on body2 (local)
    50, 50, // fixed distance
    );
    joint.space = space;

    Fully modernized — uses ZPP_DistanceJoint directly (extracted to TypeScript).

    Hierarchy (View Summary)

    Index
    • Parameters

      • body1: Body | null

        First body, or null for a static world anchor.

      • body2: Body | null

        Second body, or null for a static world anchor.

      • anchor1: Vec2

        Anchor point in body1's local space (disposed if weak).

      • anchor2: Vec2

        Anchor point in body2's local space (disposed if weak).

      • jointMin: number

        Minimum allowed distance (must be >= 0).

      • jointMax: number

        Maximum allowed distance (must be >= jointMin).

      Returns DistanceJoint

    debugDraw: boolean = true
    • get damping(): number

      Damping ratio for soft constraints (stiff = false).

      0 = undamped (oscillates freely), 1 = critically damped. Values > 1 are overdamped. Must be >= 0. Ignored when stiff is true.

      Returns number

      1

    • set damping(value: number): void

      Parameters

      • value: number

      Returns void

    • get frequency(): number

      Spring frequency in Hz for soft constraints (stiff = false).

      Higher values make the spring stiffer; lower values make it bouncier. Must be > 0. Ignored when stiff is true.

      Returns number

      10

    • set frequency(value: number): void

      Parameters

      • value: number

      Returns void

    • get isSleeping(): boolean

      Whether the constraint's simulation component is currently sleeping.

      Only valid when the constraint is active and in a space — throws otherwise.

      Returns boolean

    • get maxForce(): number

      Maximum force (in Newtons) the constraint may apply per step.

      When the required force exceeds this value the constraint becomes slack. If breakUnderForce is true the constraint breaks instead. Must be >= 0. Infinity disables the limit.

      Returns number

      Infinity

    • set maxForce(value: number): void

      Parameters

      • value: number

      Returns void

    • get userData(): Record<string, unknown>

      Arbitrary user data attached to this constraint. Lazily initialized to {} on first access.

      Returns Record<string, unknown>