# B2.World:createJoint

**Available since:** Gideros 2011.6

**Class:** b2.World

### Description

Creates a joint given a definition. All 10 types of joints are created by using this function:

```
(b2.Joint) = b2.World:createJoint(jointDef)
```

### Parameters

**jointDef**: (table)

### Return values

**Returns** (b2.Joint) created joint

### Distance Joint

Distance joint definition. This requires defining an anchor point on both bodies and the non-zero length of the distance joint. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. This helps when saving and loading a game.

**type**: (number) b2.DISTANCE_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**length**: (number) The natural length between the anchor points. Do not use a zero or short length.

**frequencyHz**: (number) The mass-spring-damper frequency in Hertz.

**dampingRatio**: (number) The damping ratio. 0 = no damping, 1 = critical damping.

Also, you can use b2.createDistanceJointDef function to create a distance joint definiton table easier.

### Friction Joint

Friction joint definition.

**type**: (number) b2.LINE_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**maxForce**: (number) The maximum friction force in N.

**maxTorque**: (number) The maximum friction torque in N-m.

### Gear Joint

Gear joint definition. This definition requires two existing revolute or prismatic joints (any combination will work). The provided joints must attach a dynamic body to a static body.

**type**: (number) b2.GEAR_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**joint1**: (b2.Joint) The first revolute/prismatic joint attached to the gear joint.

**joint2**: (b2.Joint) The second revolute/prismatic joint attached to the gear joint.

**ratio**: (number) The gear ratio.

Also, you can use b2.createGearJointDef function to create a gear joint definiton table easier.

### Mouse Joint

Mouse joint definition. This requires a world target point, tuning parameters, and the time step.

**type**: (number) b2.MOUSE_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**target**: (table) The initial world target point. This is assumed to coincide with the body anchor initially.

**maxForce**: (number) The maximum constraint force that can be exerted to move the candidate body. Usually you will express as some multiple of the weight (multiplier * mass * gravity).

**frequencyHz**: (number) The response speed.

**dampingRatio**: (number) The damping ratio. 0 = no damping, 1 = critical damping.

Also, you can use b2.createMouseJointDef function to create a mouse joint definiton table easier.

### Prismatic Joint

Prismatic joint definition. This requires defining a line of motion using an axis and an anchor point. The definition uses local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.

**type**: (number) b2.PRISMATIC_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**localAxisA**: (table) The local translation axis in bodyA.

**referenceAngle**: (number) The body2 angle minus body1 angle in the reference state (radians).

**enableLimit**: (boolean) A flag to enable joint limits.

**lowerTranslation**: (number) The lower translation limit, usually in meters.

**upperTranslation**: (number) The upper translation limit, usually in meters.

**enableMotor**: (boolean) A flag to enable the joint motor.

**maxMotorForce**: (number) The maximum motor torque, usually in N-m.

**motorSpeed**: (number) The desired motor speed in radians per second.

Also, you can use b2.createPrismaticJointDef function to create a prismatic joint definiton table easier.

### Pulley Joint

Pulley joint definition. This requires two ground anchors, two dynamic body anchor points, max lengths for each side, and a pulley ratio.

**type**: (number) b2.PULLEY_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**groundAnchorA**: (table) The first ground anchor in world coordinates. This point never moves.

**groundAnchorB**: (table) The second ground anchor in world coordinates. This point never moves.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**lengthA**: (number) The a reference length for the segment attached to bodyA.

**lengthB**: (number) The a reference length for the segment attached to bodyB.

**ratio**: (number) The pulley ratio, used to simulate a block-and-tackle.

Also, you can use b2.createPulleyJointDef function to create a pulley joint definiton table easier.

### Revolute Joint

Revolute joint definition. This requires defining an anchor point where the bodies are joined. The definition uses local anchor points so that the initial configuration can violate the constraint slightly. You also need to specify the initial relative angle for joint limits. This helps when saving and loading a game. The local anchor points are measured from the body origin rather than the center of mass because:

- you might not know where the center of mass will be
- if you add/remove shapes from a body and recompute the mass, the joints will be broken.

**type**: (number) b2.REVOLUTE_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**referenceAngle**: (number) The bodyB angle minus bodyA angle in the reference state (radians).

**enableLimit**: (boolean) A flag to enable joint limits.

**lowerAngle**: (number) The lower angle for the joint limit (radians).

**upperAngle**: (number) The upper angle for the joint limit (radians).

**enableMotor**: (boolean) A flag to enable the joint motor.

**motorSpeed**: (number) The desired motor speed. Usually in radians per second.

**maxMotorTorque**: (number) The maximum motor torque used to achieve the desired motor speed. Usually in N-m.

Also, you can use b2.createRevoluteJointDef function to create a revolute joint definiton table easier.

### Rope Joint

Rope joint definition. This requires two body anchor points and a maximum length.

**type**: (number) b2.ROPE_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**maxLength**: (number) The maximum length of the rope.

Also, you can use b2.createRopeJointDef function to create a rope joint definiton table easier.

### Weld Joint

Weld joint definition. You need to specify local anchor points where they are attached and the relative body angle. The position of the anchor points is important for computing the reaction torque.

**type**: (number) b2.WELD_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**referenceAngle**: (number) The bodyB angle minus bodyA angle in the reference state (radians).

Also, you can use b2.createWeldJointDef function to create a weld joint definiton table easier.

### Wheel Joint

Wheel joint definition. This requires defining a line of motion using an axis and an anchor point. The definition uses local anchor points and a local axis so that the initial configuration can violate the constraint slightly. The joint translation is zero when the local anchor points coincide in world space. Using local anchors and a local axis helps when saving and loading a game.

**type**: (number) b2.WHEEL_JOINT

**bodyA**: (b2.Body) The first attached body.

**bodyB**: (b2.Body) The second attached body.

**collideConnected**: (boolean) Set this flag to true if the attached bodies should collide.

**localAnchorA**: (table) The local anchor point relative to bodyA's origin.

**localAnchorB**: (table) The local anchor point relative to bodyB's origin.

**localAxisA**: (table) The local translation axis in bodyA.

**enableMotor**: (boolean) A flag to enable the joint motor.

**maxMotorTorque**: (number) The maximum motor torque, usually in N-m.

**motorSpeed**: (number) The desired motor speed in radians per second.

**frequencyHz**: (number) Suspension frequency, zero indicates no suspension.

**dampingRatio**: (number) Suspension damping ratio, one indicates critical damping.

Also, you can use b2.createWheelJointDef function to create a wheel joint definiton table easier.

### Example

```
local joint = xworld:createJoint({
type=b2.REVOLUTE_JOINT,
bodyA=prevBody, bodyB=body,
collideConnected=false,
localAnchorA={x=xactorsw, y=xactorsh/2},
localAnchorB={x=0, y=xactorsh/2},
-- ...
})
```