nape-js API
    Preparing search index...

    Class MotorJoint

    Motor joint — drives the relative angular velocity between two bodies toward a target rate, subject to maxForce.

    The motor enforces: body2.angularVel - ratio * body1.angularVel → rate

    This is a velocity-level constraint (not positional), so it does not enforce a particular relative angle — it continuously applies torque to reach rate. Use an AngleJoint in addition if you also need an angle limit.

    // Spin body2 at 2 rad/s relative to body1, limited to 500 N force
    const motor = new MotorJoint(body1, body2, 2.0);
    motor.maxForce = 500;
    motor.space = space;

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

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • body1: Body | null

        First body, or null for a static world reference.

      • body2: Body | null

        Second body, or null for a static world reference.

      • rate: number = 0.0

        Target relative angular velocity (rad/s). Default 0.0.

      • ratio: number = 1.0

        Gear ratio applied to body1's angular velocity. Default 1.0.

      Returns MotorJoint

    Properties

    debugDraw: boolean = true

    Accessors

    • get active(): boolean

      Whether the constraint is currently active (enforced by the solver).

      Deactivating a constraint suspends it without removing it from the space.

      Returns boolean

      true

    • set active(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get breakUnderError(): boolean

      When true, the constraint breaks if the positional error exceeds maxError.

      Returns boolean

      false

    • set breakUnderError(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get breakUnderForce(): boolean

      When true, the constraint breaks (fires a BREAK event) if the applied force exceeds maxForce in a single step.

      Returns boolean

      false

    • set breakUnderForce(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get cbTypes(): object

      The set of CbTypes assigned to this constraint. Used to filter which listeners respond to this constraint's events.

      Returns object

    • 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 ignore(): boolean

      When true the constraint is completely ignored by the engine — bodies are not woken, no impulse is applied, and no callbacks fire.

      Returns boolean

      false

    • set ignore(value: boolean): void

      Parameters

      • value: boolean

      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 maxError(): number

      Maximum positional error (in pixels) allowed before breaking.

      Only meaningful when breakUnderError is true. Must be >= 0. Infinity disables the limit.

      Returns number

      Infinity

    • set maxError(value: number): void

      Parameters

      • value: number

      Returns void

    • 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 ratio(): number

      Gear ratio applied to body1's angular velocity.

      The motor drives: body2.angularVel - ratio * body1.angularVel → rate

      Returns number

      1.0

    • set ratio(value: number): void

      Parameters

      • value: number

      Returns void

    • get removeOnBreak(): boolean

      When true (default), the constraint is automatically removed from its space when it breaks. Set to false to keep it in the space after breaking.

      Returns boolean

      true

    • set removeOnBreak(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get space(): Space | null

      The space this constraint belongs to, or null if not in a space.

      Assign to add/remove the constraint from a space:

      joint.space = mySpace;  // adds to space
      joint.space = null; // removes from space

      Cannot be set if the constraint belongs to a Compound.

      Returns Space | null

    • set space(value: Space | null): void

      Parameters

      Returns void

    • get stiff(): boolean

      When true (default) the constraint is stiff/rigid. When false the constraint uses a soft spring model driven by frequency and damping.

      Returns boolean

      true

    • set stiff(value: boolean): void

      Parameters

      • value: boolean

      Returns void

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

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

      Returns Record<string, unknown>

    Methods

    • The impulse applied by this constraint in the last simulation step.

      The shape of the returned MatMN depends on the constraint's degrees of freedom (e.g., 1×1 for AngleJoint/MotorJoint, 2×1 for PivotJoint/LineJoint, 3×1 for WeldJoint).

      Returns MatMN