Engine API Reference - v2.20.0-beta.0
    Preparing search index...

    Class JointComponentAlpha

    The JointComponent constrains the relative motion of two rigid bodies. The entity holding the joint component is not itself constrained - instead, its world transform defines the joint frame: the anchor point and axes that the constraint operates about. The constrained bodies are assigned via entityA and entityB, both of which must have a RigidBodyComponent. If entityB is null, entityA is constrained to a fixed point in world space.

    A joint's primary axis is the joint entity's local X axis: a hinge rotates about X, a slider translates along X and a ball joint twists about X. To aim a joint, rotate the joint entity. A common pattern is to parent the joint entity to entityA at the pivot point. For 6dof joints, each degree of freedom measures the offset of entityB (or of the world anchor when entityB is null) relative to entityA, along the joint's axes.

    The joint frames are captured when the underlying constraint is created - typically when the component is enabled and both bodies are present in the physics simulation. Moving the joint entity afterwards has no effect on an existing constraint. Call refreshFrames to re-capture the frames from the current world transforms. Entity scale is ignored, matching the behavior of rigid bodies.

    Many properties apply only to specific joint types; each one documents the types it affects, and properties without such a note (for example entityA, enableCollision and breakImpulse) apply to all types.

    To add a JointComponent to an Entity, use Entity#addComponent:

    // Create a door hinge: the joint entity's position is the hinge point and its
    // local X axis (rotated here to point up) is the hinge axis
    const hinge = new pc.Entity('hinge');
    hinge.setPosition(1, 1, 0);
    hinge.setEulerAngles(0, 0, 90);
    hinge.addComponent('joint', {
    type: pc.JOINTTYPE_HINGE,
    entityA: door,
    entityB: doorFrame,
    enableLimits: true,
    limits: new pc.Vec2(0, 110)
    });
    app.root.addChild(hinge);

    Hierarchy (View Summary)

    Index

    Properties

    entity: Entity

    The Entity that this Component is attached to.

    The ComponentSystem used to create this Component.

    Accessors

    • get angularDamping(): Vec3
      Alpha

      Gets the damping of the springs acting on rotation about the joint's X, Y and Z axes.

      Returns Vec3

    • set angularDamping(arg: Vec3): void
      Alpha

      Sets the damping of the springs acting on rotation about the joint's X, Y and Z axes. Only used by 6dof joints. Defaults to [1, 1, 1].

      Parameters

      Returns void

    • get angularEquilibrium(): Vec3
      Alpha

      Gets the rest angles of the springs acting on rotation about the joint's X, Y and Z axes.

      Returns Vec3

    • set angularEquilibrium(arg: Vec3): void
      Alpha

      Sets the rest angles of the springs acting on rotation about the joint's X, Y and Z axes, in degrees. Only used by 6dof joints. Defaults to [0, 0, 0].

      Parameters

      Returns void

    • get angularLimitsX(): Vec2
      Alpha

      Gets the lower and upper limit of rotation about the joint's X axis.

      Returns Vec2

    • set angularLimitsX(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of rotation about the joint's X axis, in degrees. For stability, keep the limits within -180 and 180 degrees. Only used by 6dof joints when angularMotionX is MOTION_LIMITED. Defaults to [0, 0].

      Parameters

      Returns void

    • get angularLimitsY(): Vec2
      Alpha

      Gets the lower and upper limit of rotation about the joint's Y axis.

      Returns Vec2

    • set angularLimitsY(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of rotation about the joint's Y axis, in degrees. For stability, keep the limits within -90 and 90 degrees. Only used by 6dof joints when angularMotionY is MOTION_LIMITED. Defaults to [0, 0].

      Parameters

      Returns void

    • get angularLimitsZ(): Vec2
      Alpha

      Gets the lower and upper limit of rotation about the joint's Z axis.

      Returns Vec2

    • set angularLimitsZ(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of rotation about the joint's Z axis, in degrees. For stability, keep the limits within -180 and 180 degrees. Only used by 6dof joints when angularMotionZ is MOTION_LIMITED. Defaults to [0, 0].

      Parameters

      Returns void

    • get angularMotionX(): "free" | "limited" | "locked"
      Alpha

      Gets the type of motion allowed for rotation about the joint's X axis.

      Returns "free" | "limited" | "locked"

    • set angularMotionX(arg: "free" | "limited" | "locked"): void
      Alpha

      Sets the type of motion allowed for rotation about the joint's X axis. Can be MOTION_LOCKED, MOTION_LIMITED or MOTION_FREE. Only used by 6dof joints. Defaults to MOTION_LOCKED.

      Parameters

      • arg: "free" | "limited" | "locked"

      Returns void

    • get angularMotionY(): "free" | "limited" | "locked"
      Alpha

      Gets the type of motion allowed for rotation about the joint's Y axis.

      Returns "free" | "limited" | "locked"

    • set angularMotionY(arg: "free" | "limited" | "locked"): void
      Alpha

      Sets the type of motion allowed for rotation about the joint's Y axis. Can be MOTION_LOCKED, MOTION_LIMITED or MOTION_FREE. Only used by 6dof joints. Defaults to MOTION_LOCKED.

      Parameters

      • arg: "free" | "limited" | "locked"

      Returns void

    • get angularMotionZ(): "free" | "limited" | "locked"
      Alpha

      Gets the type of motion allowed for rotation about the joint's Z axis.

      Returns "free" | "limited" | "locked"

    • set angularMotionZ(arg: "free" | "limited" | "locked"): void
      Alpha

      Sets the type of motion allowed for rotation about the joint's Z axis. Can be MOTION_LOCKED, MOTION_LIMITED or MOTION_FREE. Only used by 6dof joints. Defaults to MOTION_LOCKED.

      Parameters

      • arg: "free" | "limited" | "locked"

      Returns void

    • get angularStiffness(): Vec3
      Alpha

      Gets the stiffness of the springs acting on rotation about the joint's X, Y and Z axes.

      Returns Vec3

    • set angularStiffness(arg: Vec3): void
      Alpha

      Sets the stiffness of the springs acting on rotation about the joint's X, Y and Z axes. A spring acts on an axis when its stiffness component is greater than 0. Only used by 6dof joints. Defaults to [0, 0, 0] (no springs).

      Parameters

      Returns void

    • get breakImpulse(): number
      Alpha

      Gets the impulse threshold above which the joint breaks.

      Returns number

    • set breakImpulse(impulse: number): void
      Alpha

      Sets the impulse threshold, in Newton seconds, above which the joint breaks. A broken joint no longer constrains its bodies, fires the 'break' event and has isBroken set to true. As a rule of thumb, a steady force breaks the joint when force × simulation timestep exceeds this value. Defaults to Infinity (unbreakable).

      Parameters

      • impulse: number

      Returns void

    • get enableCollision(): boolean
      Alpha

      Gets whether the two constrained bodies can collide with each other.

      Returns boolean

    • set enableCollision(enableCollision: boolean): void
      Alpha

      Sets whether the two constrained bodies can collide with each other. Defaults to false.

      Parameters

      • enableCollision: boolean

      Returns void

    • get enabled(): boolean
      Alpha

      Gets the enabled state of the component.

      Returns boolean

    • set enabled(value: boolean): void
      Alpha

      Sets the enabled state of the component.

      Parameters

      • value: boolean

      Returns void

    • get enableLimits(): boolean
      Alpha

      Gets whether the joint's limits are enabled.

      Returns boolean

    • set enableLimits(arg: boolean): void
      Alpha

      Sets whether the joint's limits are enabled. For hinge joints, this limits rotation about the joint's X axis to limits. For slider joints, this limits travel along the joint's X axis to limits. For ball joints, this limits rotation to swingLimitY, swingLimitZ and twistLimit. Not used by fixed and 6dof joints. Defaults to false.

      Parameters

      • arg: boolean

      Returns void

    • get entityA(): Entity | null
      Alpha

      Gets the first entity constrained by this joint.

      Returns Entity | null

    • set entityA(arg: Entity | null): void
      Alpha

      Sets the first entity constrained by this joint. The entity must have a RigidBodyComponent. Can be set to an Entity or the GUID of an entity. The constraint is created once both constrained entities have rigid bodies in the simulation.

      Parameters

      Returns void

    • get entityB(): Entity | null
      Alpha

      Gets the second entity constrained by this joint.

      Returns Entity | null

    • set entityB(arg: Entity | null): void
      Alpha

      Sets the second entity constrained by this joint. The entity must have a RigidBodyComponent. Can be set to an Entity or the GUID of an entity. If null, entityA is constrained to a fixed point in world space instead. Defaults to null.

      Parameters

      Returns void

    • get isBroken(): boolean
      Alpha

      Gets whether the joint has broken as a result of the applied impulse exceeding breakImpulse. A broken joint is re-armed by calling refreshFrames, toggling Component#enabled or changing type, entityA or entityB.

      Returns boolean

    • get limits(): Vec2
      Alpha

      Gets the lower and upper limit of the joint's primary degree of freedom.

      Returns Vec2

    • set limits(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of the joint's primary degree of freedom. For hinge joints, these are angles of rotation about the joint's X axis, in degrees; for slider joints, distances along the joint's X axis, in meters. Only used by hinge and slider joints, when enableLimits is true. (Ball joints limit motion with swingLimitY, swingLimitZ and twistLimit; 6dof joints use linearLimitsX and angularLimitsX etc.) Defaults to [-45, 45].

      Parameters

      Returns void

    • get linearDamping(): Vec3
      Alpha

      Gets the damping of the springs acting on translation along the joint's X, Y and Z axes.

      Returns Vec3

    • set linearDamping(arg: Vec3): void
      Alpha

      Sets the damping of the springs acting on translation along the joint's X, Y and Z axes. Only used by 6dof joints. Defaults to [1, 1, 1].

      Parameters

      Returns void

    • get linearEquilibrium(): Vec3
      Alpha

      Gets the rest positions of the springs acting on translation along the joint's X, Y and Z axes.

      Returns Vec3

    • set linearEquilibrium(arg: Vec3): void
      Alpha

      Sets the rest positions of the springs acting on translation along the joint's X, Y and Z axes, in meters. Only used by 6dof joints. Defaults to [0, 0, 0].

      Parameters

      Returns void

    • get linearLimitsX(): Vec2
      Alpha

      Gets the lower and upper limit of translation along the joint's X axis.

      Returns Vec2

    • set linearLimitsX(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of translation along the joint's X axis, in meters. Only used by 6dof joints when linearMotionX is MOTION_LIMITED. Defaults to [0, 0].

      Parameters

      Returns void

    • get linearLimitsY(): Vec2
      Alpha

      Gets the lower and upper limit of translation along the joint's Y axis.

      Returns Vec2

    • set linearLimitsY(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of translation along the joint's Y axis, in meters. Only used by 6dof joints when linearMotionY is MOTION_LIMITED. Defaults to [0, 0].

      Parameters

      Returns void

    • get linearLimitsZ(): Vec2
      Alpha

      Gets the lower and upper limit of translation along the joint's Z axis.

      Returns Vec2

    • set linearLimitsZ(arg: Vec2): void
      Alpha

      Sets the lower and upper limit of translation along the joint's Z axis, in meters. Only used by 6dof joints when linearMotionZ is MOTION_LIMITED. Defaults to [0, 0].

      Parameters

      Returns void

    • get linearMotionX(): "free" | "limited" | "locked"
      Alpha

      Gets the type of motion allowed for translation along the joint's X axis.

      Returns "free" | "limited" | "locked"

    • set linearMotionX(arg: "free" | "limited" | "locked"): void
      Alpha

      Sets the type of motion allowed for translation along the joint's X axis. Can be MOTION_LOCKED, MOTION_LIMITED or MOTION_FREE. Only used by 6dof joints. Defaults to MOTION_LOCKED.

      Parameters

      • arg: "free" | "limited" | "locked"

      Returns void

    • get linearMotionY(): "free" | "limited" | "locked"
      Alpha

      Gets the type of motion allowed for translation along the joint's Y axis.

      Returns "free" | "limited" | "locked"

    • set linearMotionY(arg: "free" | "limited" | "locked"): void
      Alpha

      Sets the type of motion allowed for translation along the joint's Y axis. Can be MOTION_LOCKED, MOTION_LIMITED or MOTION_FREE. Only used by 6dof joints. Defaults to MOTION_LOCKED.

      Parameters

      • arg: "free" | "limited" | "locked"

      Returns void

    • get linearMotionZ(): "free" | "limited" | "locked"
      Alpha

      Gets the type of motion allowed for translation along the joint's Z axis.

      Returns "free" | "limited" | "locked"

    • set linearMotionZ(arg: "free" | "limited" | "locked"): void
      Alpha

      Sets the type of motion allowed for translation along the joint's Z axis. Can be MOTION_LOCKED, MOTION_LIMITED or MOTION_FREE. Only used by 6dof joints. Defaults to MOTION_LOCKED.

      Parameters

      • arg: "free" | "limited" | "locked"

      Returns void

    • get linearStiffness(): Vec3
      Alpha

      Gets the stiffness of the springs acting on translation along the joint's X, Y and Z axes.

      Returns Vec3

    • set linearStiffness(arg: Vec3): void
      Alpha

      Sets the stiffness of the springs acting on translation along the joint's X, Y and Z axes. A spring acts on an axis when its stiffness component is greater than 0. Only used by 6dof joints. Defaults to [0, 0, 0] (no springs).

      Parameters

      Returns void

    • get maxMotorForce(): number
      Alpha

      Gets the maximum force the joint's motor can apply.

      Returns number

    • set maxMotorForce(arg: number): void
      Alpha

      Sets the maximum force the motor can apply to reach motorSpeed. For hinge joints, this is a torque in Newton meters; for slider joints, a force in Newtons. The motor is disabled while this is 0, so set it greater than 0 to engage the motor. Only used by hinge and slider joints. Defaults to 0.

      Parameters

      • arg: number

      Returns void

    • get motorSpeed(): number
      Alpha

      Gets the target speed the motor drives towards.

      Returns number

    • set motorSpeed(arg: number): void
      Alpha

      Sets the target speed the motor drives towards. For hinge joints, this is an angular speed in degrees per second; for slider joints, a linear speed in meters per second. The motor is active only while maxMotorForce is greater than 0; with a target speed of 0 and a positive force the motor acts as a brake, holding the joint at rest. Only used by hinge and slider joints. Defaults to 0.

      Parameters

      • arg: number

      Returns void

    • get swingLimitY(): number
      Alpha

      Gets the maximum swing of a ball joint towards its Y axis.

      Returns number

    • set swingLimitY(arg: number): void
      Alpha

      Sets the maximum swing of a ball joint towards its Y axis, in degrees, measured as a half-angle either side of the joint's X axis. Only used by ball joints when enableLimits is true. Defaults to 45.

      Parameters

      • arg: number

      Returns void

    • get swingLimitZ(): number
      Alpha

      Gets the maximum swing of a ball joint towards its Z axis.

      Returns number

    • set swingLimitZ(arg: number): void
      Alpha

      Sets the maximum swing of a ball joint towards its Z axis, in degrees, measured as a half-angle either side of the joint's X axis. Only used by ball joints when enableLimits is true. Defaults to 45.

      Parameters

      • arg: number

      Returns void

    • get twistLimit(): number
      Alpha

      Gets the maximum twist of a ball joint about its X axis.

      Returns number

    • set twistLimit(arg: number): void
      Alpha

      Sets the maximum twist of a ball joint about its X axis, in degrees, measured as a half-angle either side of the rest orientation. Only used by ball joints when enableLimits is true. Defaults to 20.

      Parameters

      • arg: number

      Returns void

    • get type(): "fixed" | "ball" | "hinge" | "slider" | "6dof"
      Alpha

      Gets the type of joint.

      Returns "fixed" | "ball" | "hinge" | "slider" | "6dof"

    • set type(type: "fixed" | "ball" | "hinge" | "slider" | "6dof"): void
      Alpha

      Sets the type of joint. Can be:

      • JOINTTYPE_FIXED: rigidly locks the bodies together.
      • JOINTTYPE_BALL: ball and socket - free rotation about the anchor point, with optional swing and twist limits.
      • JOINTTYPE_HINGE: rotation about the joint's X axis, with optional limits and motor.
      • JOINTTYPE_SLIDER: translation along the joint's X axis, with optional limits and motor.
      • JOINTTYPE_6DOF: each linear and angular axis is independently locked, limited or free, with optional springs.

      Defaults to JOINTTYPE_FIXED.

      Parameters

      • type: "fixed" | "ball" | "hinge" | "slider" | "6dof"

      Returns void

    Methods

    • Alpha

      Fire an event, all additional arguments are passed on to the event listener.

      Parameters

      • name: string

        Name of event to fire.

      • Optionalarg1: any

        First argument that is passed to the event handler.

      • Optionalarg2: any

        Second argument that is passed to the event handler.

      • Optionalarg3: any

        Third argument that is passed to the event handler.

      • Optionalarg4: any

        Fourth argument that is passed to the event handler.

      • Optionalarg5: any

        Fifth argument that is passed to the event handler.

      • Optionalarg6: any

        Sixth argument that is passed to the event handler.

      • Optionalarg7: any

        Seventh argument that is passed to the event handler.

      • Optionalarg8: any

        Eighth argument that is passed to the event handler.

      Returns EventHandler

      Self for chaining.

      obj.fire('test', 'This is the message');
      
    • Alpha

      Test if there are any handlers bound to an event name.

      Parameters

      • name: string

        The name of the event to test.

      Returns boolean

      True if the object has handlers bound to the specified event name.

      obj.on('test', () => {}); // bind an event to 'test'
      obj.hasEvent('test'); // returns true
      obj.hasEvent('hello'); // returns false
    • Alpha

      Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.

      Parameters

      • Optionalname: string

        Name of the event to unbind.

      • Optionalcallback: HandleEventCallback

        Function to be unbound.

      • Optionalscope: any

        Scope that was used as the this when the event is fired.

      Returns EventHandler

      Self for chaining.

      const handler = () => {};
      obj.on('test', handler);

      obj.off(); // Removes all events
      obj.off('test'); // Removes all events called 'test'
      obj.off('test', handler); // Removes all handler functions, called 'test'
      obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
    • Alpha

      Attach an event handler to an event.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      Can be used for removing event in the future.

      obj.on('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      const evt = obj.on('test', (a, b) => {
      console.log(a + b);
      });
      // some time later
      evt.off();
    • Alpha

      Returns void

    • Alpha

      Attach an event handler to an event. This handler will be removed after being fired once.

      Parameters

      • name: string

        Name of the event to bind the callback to.

      • callback: HandleEventCallback

        Function that is called when event is fired. Note the callback is limited to 8 arguments.

      • Optionalscope: any = ...

        Object to use as 'this' when the event is fired, defaults to current this.

      Returns EventHandle

      Can be used for removing event in the future.

      obj.once('test', (a, b) => {
      console.log(a + b);
      });
      obj.fire('test', 1, 2); // prints 3 to the console
      obj.fire('test', 1, 2); // not going to get handled
    • Alpha

      Destroys and recreates the underlying constraint, re-capturing the joint frames from the current world transforms of the joint entity, entityA and entityB. Call this after moving the joint entity to re-anchor the joint, or to re-attach a joint that has broken.

      Returns void

    Events

    EVENT_BREAK: string = 'break'

    Fired when the applied impulse on the joint exceeds breakImpulse and the constraint breaks. The broken joint no longer constrains its bodies and isBroken becomes true. Call refreshFrames to re-attach it. Note that on ammo builds that expose no constraint state, breakage of 6dof joints cannot be detected, so this event does not fire for them - other joint types are unaffected.

    entity.joint.on('break', () => {
    console.log('The joint broke');
    });