Skip to main content

Joint Class

Description:

  A factory class to create different types of joints that can be used to connect physics bodies together.

distance

Type: Function.

Description:

  Creates a distance joint between two physics bodies.

Signature:

distance: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
anchorA: Vec2,
anchorB: Vec2,
frequency?: number --[[0.0]],
damping?: number --[[0.0]]): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the physics body connected to joint will collide with each other.
bodyABodyThe first physics body to connect with the joint.
bodyBBodyThe second physics body to connect with the joint.
anchorAVec2The position of the joint on the first physics body.
anchorBVec2The position of the joint on the second physics body.
frequencynumberThe frequency of the joint, in Hertz (default is 0.0).
dampingnumberThe damping ratio of the joint (default is 0.0).

Returns:

Return TypeDescription
JointThe new distance joint.

friction

Type: Function.

Description:

  Creates a friction joint between two physics bodies.

Signature:

friction: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
worldPos: Vec2,
maxForce: number,
maxTorque: number): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the physics body connected to joint will collide with each other.
bodyABodyThe first physics body to connect with the joint.
bodyBBodyThe second physics body to connect with the joint.
worldPosVec2The position of the joint in the game world.
maxForcenumberThe maximum force that can be applied to the joint.
maxTorquenumberThe maximum torque that can be applied to the joint.

Returns:

Return TypeDescription
JointThe new friction joint.

gear

Type: Function.

Description:

  Creates a gear joint between two other joints.

Signature:

gear: function(self: JointClass,
canCollide: boolean,
jointA: Joint,
jointB: Joint,
ratio?: number --[[1.0]]): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the physics bodies connected to the joint can collide with each other.
jointAJointThe first joint to connect with the gear joint.
jointBJointThe second joint to connect with the gear joint.
rationumberThe gear ratio (default is 1.0).

Returns:

Return TypeDescription
JointThe new gear joint.

spring

Type: Function.

Description:

  Creates a new spring joint between the two specified bodies.

Signature:

spring: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
linearOffset: Vec2,
angularOffset: number,
maxForce: number,
maxTorque: number,
correctionFactor?: number --[[1.0]]): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether the connected bodies should collide with each other.
bodyABodyThe first body connected to the joint.
bodyBBodyThe second body connected to the joint.
linearOffsetVec2Position of body-B minus the position of body-A, in body-A's frame.
angularOffsetnumberAngle of body-B minus angle of body-A.
maxForcenumberThe maximum force the joint can exert.
maxTorquenumberThe maximum torque the joint can exert.
correctionFactornumberOptional correction factor, defaults to 1.0.

Returns:

Return TypeDescription
JointThe created joint.

move

Type: Function.

Description:

  Creates a new move joint for the specified body.

Signature:

move: function(self: JointClass,
canCollide: boolean,
body: Body,
targetPos: Vec2,
maxForce: number,
frequency?: number --[[5.0]],
damping?: number --[[0.7]]): MoveJoint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether the body can collide with other bodies
bodyBodyThe body that the joint is attached to.
targetPosVec2The target position that the body should move towards.
maxForcenumberThe maximum force the joint can exert.
frequencynumberOptional frequency ratio, defaults to 5.0.
dampingnumberOptional damping ratio, defaults to 0.7.

Returns:

Return TypeDescription
MoveJointThe created move joint.

prismatic

Type: Function.

Description:

  Creates a new prismatic joint between the two specified bodies.

Signature:

prismatic: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
worldPos: Vec2,
axisAngle: number,
lowerTranslation?: number --[[0.0]],
upperTranslation?: number --[[0.0]],
maxMotorForce?: number --[[0.0]],
motorSpeed?: number --[[0.0]]): MotorJoint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether the connected bodies should collide with each other.
bodyABodyThe first body connected to the joint.
bodyBBodyThe second body connected to the joint.
worldPosVec2The world position of the joint.
axisAnglenumberThe axis angle of the joint.
lowerTranslationnumberOptional lower translation limit, defaults to 0.0.
upperTranslationnumberOptional upper translation limit, defaults to 0.0.
maxMotorForcenumberOptional maximum motor force, defaults to 0.0.
motorSpeednumberOptional motor speed, defaults to 0.0.

Returns:

Return TypeDescription
MotorJointThe created prismatic joint.

pulley

Type: Function.

Description:

  Create a pulley joint between two physics bodies.

Signature:

pulley: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
anchorA: Vec2,
anchorB: Vec2,
groundAnchorA: Vec2,
groundAnchorB: Vec2,
ratio?: number --[[1.0]]): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the connected bodies will collide with each other.
bodyABodyThe first physics body to connect.
bodyBBodyThe second physics body to connect.
anchorAVec2The position of the anchor point on the first body.
anchorBVec2The position of the anchor point on the second body.
groundAnchorAVec2The position of the ground anchor point on the first body in world coordinates.
groundAnchorBVec2The position of the ground anchor point on the second body in world coordinates.
rationumber[optinal] The pulley ratio (default 1.0).

Returns:

Return TypeDescription
JointThe pulley joint.

revolute

Type: Function.

Description:

  Create a revolute joint between two physics bodies.

Signature:

revolute: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
worldPos: Vec2,
lowerAngle?: number --[[0.0]],
upperAngle?: number --[[0.0]],
maxMotorTorque?: number --[[0.0]],
motorSpeed?: number --[[0.0]]): MotorJoint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the connected bodies will collide with each other.
bodyABodyThe first physics body to connect.
bodyBBodyThe second physics body to connect.
worldPosVec2The position in world coordinates where the joint will be created.
lowerAnglenumber[optinal] The lower angle limit (radians) (default 0.0).
upperAnglenumber[optinal] The upper angle limit (radians) (default 0.0).
maxMotorTorquenumber[optinal] The maximum torque that can be applied to the joint to achieve the target speed (default 0.0).
motorSpeednumber[optinal] The desired speed of the joint (default 0.0).

Returns:

Return TypeDescription
MotorJointThe revolute joint.

rope

Type: Function.

Description:

  Create a rope joint between two physics bodies.

Signature:

rope: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
anchorA: Vec2,
anchorB: Vec2,
maxLength: number): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the connected bodies will collide with each other.
bodyABodyThe first physics body to connect.
bodyBBodyThe second physics body to connect.
anchorAVec2The position of the anchor point on the first body.
anchorBVec2The position of the anchor point on the second body.
maxLengthnumber[optinal] The maximum distance between the anchor points (default 0.0).

Returns:

Return TypeDescription
JointThe rope joint.

weld

Type: Function.

Description:

  Creates a weld joint between two bodies.

Signature:

weld: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
worldPos: Vec2,
frequency?: number --[[0.0]],
damping?: number --[[0.0]]): Joint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the bodies connected to the joint can collide with each other.
bodyABodyThe first body to be connected by the joint.
bodyBBodyThe second body to be connected by the joint.
worldPosVec2The position in the world to connect the bodies together.
frequencynumber[optional] The frequency at which the joint should be stiff, defaults to 0.0.
dampingnumber[optional] The damping rate of the joint, defaults to 0.0.

Returns:

Return TypeDescription
JointThe newly created weld joint.

wheel

Type: Function.

Description:

  Creates a wheel joint between two bodies.

Signature:

wheel: function(self: JointClass,
canCollide: boolean,
bodyA: Body,
bodyB: Body,
worldPos: Vec2,
axisAngle: number,
maxMotorTorque?: number --[[0.0]],
motorSpeed?: number --[[0.0]],
frequency?: number --[[2.0]],
damping?: number --[[0.7]]): MotorJoint

Parameters:

ParameterTypeDescription
canCollidebooleanWhether or not the bodies connected to the joint can collide with each other.
bodyABodyThe first body to be connected by the joint.
bodyBBodyThe second body to be connected by the joint.
worldPosVec2The position in the world to connect the bodies together.
axisAnglenumberThe angle of the joint axis in radians.
maxMotorTorquenumber[optional] The maximum torque the joint motor can exert, defaults to 0.0.
motorSpeednumber[optional] The target speed of the joint motor, defaults to 0.0.
frequencynumber[optional] The frequency at which the joint should be stiff, defaults to 2.0.
dampingnumber[optional] The damping rate of the joint, defaults to 0.7.

Returns:

Return TypeDescription
MotorJointThe newly created wheel joint.

__call

Type: Metamethod.

Description:

  Creates a joint instance based on the given joint definition and item dictionary containing physics bodies to be connected by joint.

Signature:

metamethod __call: function(self: JointClass, def: JointDef, itemDict: Dictionary): Joint

Parameters:

ParameterTypeDescription
defJointDefThe joint definition.
itemDictDictionaryThe dictionary containing all the bodies and other required items.

Returns:

Return TypeDescription
JointThe newly created joint.