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 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>

    Methods