API Docs for: 0.7.1
Show:

# DistanceConstraint Class

Extends Constraint

Constraint that tries to keep the distance between two bodies constant.

## Constructor

### `DistanceConstraint`

(
• `bodyA`
• `bodyB`
• `[options]`
)

#### Parameters:

• `bodyA` Body
• `bodyB` Body
• `[options]` Object optional
• `[distance]` Number optional

The distance to keep between the anchor points. Defaults to the current distance between the bodies.

• `[localAnchorA] The anchor point for bodyA, defined locally in bodyA frame. Defaults to [0,0]` Array optional

.

• `[localAnchorB] The anchor point for bodyB, defined locally in bodyB frame. Defaults to [0,0]` Array optional

.

• `[maxForce=Number.MAX_VALUE]` Object optional

Maximum force to apply.

#### Example:

``````// If distance is not given as an option, then the current distance between the bodies is used.
// In this example, the bodies will be constrained to have a distance of 2 between their centers.
var bodyA = new Body({ mass: 1, position: [-1, 0] });
var bodyB = new Body({ mass: 1, position: [1, 0] });
var constraint = new DistanceConstraint(bodyA, bodyB);
``````
``````// Manually set the distance and anchors
var constraint = new DistanceConstraint(bodyA, bodyB, {
distance: 1,          // Distance to keep between the points
localAnchorA: [1, 0], // Point on bodyA
localAnchorB: [-1, 0] // Point on bodyB
});
``````

## Methods

### `getMaxForce`

() Number

Get the max force

Number:

### `setMaxForce`

(
• `maxForce`
)

Set the max force to be used

#### Parameters:

• `maxForce` Number

### `setRelaxation`

(
• `relaxation`
)

Set relaxation for this constraint.

#### Parameters:

• `relaxation` Number

### `setStiffness`

(
• `stiffness`
)

Set stiffness for this constraint.

#### Parameters:

• `stiffness` Number

### `update`

()

Update the constraint equations. Should be done if any of the bodies changed position, before solving.

## Properties

### `bodyA`

Body

First body participating in the constraint.

### `bodyB`

Body

Second body participating in the constraint.

### `collideConnected`

Boolean

Set to true if you want the connected bodies to collide.

Default: true

### `distance`

Number

The distance to keep.

### `equations`

Array

Equations to be solved in this constraint

### `localAnchorA`

Array

Local anchor in body A.

### `localAnchorB`

Array

Local anchor in body B.

### `lowerLimit`

Number

The lower constraint limit.

### `lowerLimitEnabled`

Boolean

If the lower limit is enabled or not.

### `maxForce`

Number

Max force to apply.

### `position`

Number

Current constraint position. This is equal to the current distance between the world anchor points.

### `type`

Number

The type of constraint. May be one of Constraint.DISTANCE, Constraint.GEAR, Constraint.LOCK, Constraint.PRISMATIC or Constraint.REVOLUTE.

### `upperLimit`

Number

The upper constraint limit.

### `upperLimitEnabled`

Boolean

If the upper limit is enabled or not.