Skip to content

Class: GearJoint ​

A gear joint is used to connect two joints together. Either joint can be a revolute or prismatic joint. You specify a gear ratio to bind the motions together: coordinate1 + ratio * coordinate2 = constant

The ratio can be negative or positive. If one joint is a revolute joint and the other joint is a prismatic joint, then the ratio will have units of length or units of 1/length. Warning: You have to manually destroy the gear joint if joint1 or joint2 is destroyed.

This definition requires two existing revolute or prismatic joints (any combination will work).

Extends ​

Constructors ​

Constructor ​

new GearJoint(def): GearJoint

Parameters ​

def ​

GearJointDef

Returns ​

GearJoint

Overrides ​

Joint.constructor

Constructor ​

new GearJoint(def, bodyA, bodyB, joint1, joint2, ratio?): GearJoint

Parameters ​

def ​

GearJointOpt

bodyA ​

Body

bodyB ​

Body

joint1 ​

RevoluteJoint | PrismaticJoint

joint2 ​

RevoluteJoint | PrismaticJoint

ratio? ​

number

Returns ​

GearJoint

Overrides ​

Joint.constructor

Properties ​

style ​

style: Style = {}

Styling for dev-tools.

Inherited from ​

Joint.style


TYPE ​

static TYPE: "gear-joint"

Methods ​

getAnchorA() ​

getAnchorA(): Vec2

Get the anchor point on bodyA in world coordinates.

Returns ​

Vec2

Overrides ​

Joint.getAnchorA


getAnchorB() ​

getAnchorB(): Vec2

Get the anchor point on bodyB in world coordinates.

Returns ​

Vec2

Overrides ​

Joint.getAnchorB


getBodyA() ​

getBodyA(): Body

Get the first body attached to this joint.

Returns ​

Body

Inherited from ​

Joint.getBodyA


getBodyB() ​

getBodyB(): Body

Get the second body attached to this joint.

Returns ​

Body

Inherited from ​

Joint.getBodyB


getCollideConnected() ​

getCollideConnected(): boolean

Get collide connected. Note: modifying the collide connect flag won't work correctly because the flag is only checked when fixture AABBs begin to overlap.

Returns ​

boolean

Inherited from ​

Joint.getCollideConnected


getJoint1() ​

getJoint1(): Joint

Get the first joint.

Returns ​

Joint


getJoint2() ​

getJoint2(): Joint

Get the second joint.

Returns ​

Joint


getNext() ​

getNext(): Joint

Get the next joint the world joint list.

Returns ​

Joint

Inherited from ​

Joint.getNext


getRatio() ​

getRatio(): number

Get the gear ratio.

Returns ​

number


getReactionForce() ​

getReactionForce(inv_dt): Vec2

Get the reaction force on bodyB at the joint anchor in Newtons.

Parameters ​

inv_dt ​

number

Returns ​

Vec2

Overrides ​

Joint.getReactionForce


getReactionTorque() ​

getReactionTorque(inv_dt): number

Get the reaction torque on bodyB in N*m.

Parameters ​

inv_dt ​

number

Returns ​

number

Overrides ​

Joint.getReactionTorque


getType() ​

getType(): string

Get the type of the concrete joint.

Returns ​

string

Inherited from ​

Joint.getType


getUserData() ​

getUserData(): unknown

Returns ​

unknown

Inherited from ​

Joint.getUserData


initVelocityConstraints() ​

initVelocityConstraints(step): void

Parameters ​

step ​

TimeStep

Returns ​

void

Overrides ​

Joint.initVelocityConstraints


isActive() ​

isActive(): boolean

Short-cut function to determine if either body is inactive.

Returns ​

boolean

Inherited from ​

Joint.isActive


setRatio() ​

setRatio(ratio): void

Set the gear ratio.

Parameters ​

ratio ​

number

Returns ​

void


setUserData() ​

setUserData(data): void

Parameters ​

data ​

unknown

Returns ​

void

Inherited from ​

Joint.setUserData


shiftOrigin() ​

shiftOrigin(newOrigin): void

Shift the origin for any points stored in world coordinates.

Parameters ​

newOrigin ​

Vec2Value

Returns ​

void

Inherited from ​

Joint.shiftOrigin


solvePositionConstraints() ​

solvePositionConstraints(step): boolean

This returns true if the position errors are within tolerance.

Parameters ​

step ​

TimeStep

Returns ​

boolean

Overrides ​

Joint.solvePositionConstraints


solveVelocityConstraints() ​

solveVelocityConstraints(step): void

Parameters ​

step ​

TimeStep

Returns ​

void

Overrides ​

Joint.solveVelocityConstraints