A Constraint object can be constructed with one of:
Constructors for constraints take many common parameters which are listed below
{
stiff : true,
frequency : 10,
damping : 1,
maxForce : Number.POSITIVE_INFINITY,
maxError : Number.POSITIVE_INFINITY,
removeOnBreak : true,
breakUnderForce : false,
breakUnderError : false,
ignoreInteractions : false,
sleeping : false,
disabled : false,
userData : null
}
Defines whether a positional constraint has its positional errors solved rigidly together with contact errors, or whether positional errors are resolved through mutations of the velocity constraint making the constraint elastic.
An elastic constraint is implemented in such a way that high frequency and damping will not cause the constraint to blow up.
This parameter has no effect on velocity-only constraints such as the MotorConstraint.
Default value is true.
Defines the frequency of the constraint’s elastic behavior when positional constraint is non-stiff.
This value must be strictly positive.
This parameter has no effect on velocity-only constraints such as the MotorConstraint, or when a position constraint is stiff.
Default value is 10.
Defines the damping of the constraint’s elastic behavior when positional constraint is non-stiff.
This value must be positive.
This parameter has no effect on velocity-only constraints such as the MotorConstraint, or when a position constraint is stiff.
Default value is 1.
Defines for non-stiff positional constraints, and for velocity-only constraints the maximum amount of force that may be used when solving errors in velocity.
This value must be positive.
When such a constraint has also breakUnderForce set to true. This value defines the limit at which the constraint will be broken.
Default value is Number.POSITIVE_INFINITY.
Defines for positional constraints, the maximum amount of error which will either be solved (For non-stiff constraints) per second, or the limit at which the constraint will be broken if breakUnderError is also true.
This parameter has no effect on velocity-only constraints such as the MotorConstraint.
This value must be positive.
Default value is Number.POSITIVE_INFINITY.
Defines behavior for when this constraint is broken.
When true, the constraint will be removed from the simulation World when broken.
When false, the constraint will remain in the world, but will become disabled.
Default value is true.
For non-stiff positional constraints, and velocity-only constraints this parameter defines whether upon reaching the maxForce parameter, the constraint will either limit the amount of force it uses, or be broken.
Default value is false.
For positional constraints, this parameter defines whether upon reaching the maxError parameter, the amount of error resolved will be clamped (For non-stiff constraints, otherwise ignored) or broken (Both stiff and non-stiff constraints).
Default value is false.
Defines whether the participating RigidBody objects used by this constraint will be permitted to interact (Whether as sensors, or colliders).
Default value is false.
Define if the constraint is to be created in a sleeping state. When added to a World object, the constraint will remain asleep until woken.
Default value is false.
Define whether the constraint will be created as already disabled.
Disabling a constraint permits it to remain inside of a World, but acting as though it is not, with no side effects beyond the constraint being present in the RigidBody object’s constraints list, and being removed when a related RigidBody is removed from the world.
Default value is false.
A field in which to store whatever data you may like.
Default value is null.
Summary
Configure common constraint parameters.
Syntax
constraint.configure({
stiff : true,
frequency : 10,
damping : 1,
maxForce : Number.POSITIVE_INFINITY,
maxError : Number.POSITIVE_INFINITY,
removeOnBreak : true,
breakUnderForce : false,
breakUnderError : false,
ignoreInteractions : false
});
All parameters of the object are optional, and leaving unspecified will leave said parameter untouched.
Summary
Manually wake this Constraint.
Waking a constraint manually is not generally required. It is only ever required to manually wake a constraint, if you manually put it to sleep or added it as a sleeping constraint.
Mutations to the constraint, and interactions with related rigid bodies in the world will otherwise automatically wake the constraint.
Syntax
constraint.wake();
Summary
Manually put this Constraint to sleep.
This constraint will be woken as soon as it is interacted with in a World, or is mutated in any way that would require it to wake up in normal circumstances.
Syntax
constraint.sleep();
Summary
Query whether this constraint is currently enabled.
Syntax
var enabled = constraint.isEnabled();
Summary
Query whether this constraint is currently disabled.
Syntax
var disabled = constraint.isDisabled();
Summary
Add a new event listener for this Constraint.
Syntax
var success = constraint.addEventListener(eventType, handler);
One of:
Function to be called when this event occurs (Noting that events as usual are deferred until the end of the world step()).
Function is called with no arguments, and with its this object as the Constraint to which the event relates.
This function will fail, and return false if the event type was not accepted, or if the handler already exists for the given event type.
Example:
function breakHandler() {
console.log("Constraint named: " + this.userData.name + "was broken :(");
}
constraint.userData = {
name : "Constraint no. 1"
};
constraint.addEventListener('break', breakHandler);
You may add as many handlers for a given event type as you wish, and handlers will be called in the same order in which they were added.
Summary
Remove existing event listener from this Constraint.
Syntax
var success = constraint.removeEventListener(eventType, handler);
This function will fail, and return false if the event type was not accepted, or if the handler was not found on the constraint for the given event type.
Summary
Query the impulse applied to the given RigidBody by this constraint in the previous simulation step.
The impulse returned is of 3 dimensions, the third equal to the angular impulse the constraint applied.
Syntax
var impulse = constraint.getImpulseForBody(body);
// or
constraint.getImpulseForBody(body, impulse);
Should the input body be unrelated to this constraint, the impulse returned will be [0, 0, 0]
Summary
Get local anchor point on first rigid body.
Syntax
var anchor = constraint.getAnchorA();
// or
constraint.getAnchorA(anchor);
Note
Available for constraint types: Point, Distance, Pulley, Weld, Line only.
Summary
Set the local anchor point on first rigid body.
Syntax
constraint.setAnchorA(anchor);
Note
Available for constraint types: Point, Distance, Pulley, Weld, Line only.
Summary
Get local anchor point on second rigid body.
Syntax
var anchor = constraint.getAnchorB();
// or
constraint.getAnchorB(anchor);
Note
Available for constraint types: Point, Distance, Pulley, Weld, Line only.
Summary
Set the local anchor point on second rigid body.
Syntax
constraint.setAnchorB(anchor);
Note
Available for constraint types: Point, Distance, Pulley, Weld, Line only.
Summary
Get local anchor point on third rigid body.
Syntax
var anchor = constraint.getAnchorC();
// or
constraint.getAnchorC(anchor);
Note
Available for constraint type Pulley only.
Summary
Set the local anchor point on third rigid body.
Syntax
constraint.setAnchorC(anchor);
Note
Available for constraint type Pulley only.
Summary
Get local anchor point on fourth rigid body.
Syntax
var anchor = constraint.getAnchorD();
// or
constraint.getAnchorD(anchor);
Note
Available for constraint type Pulley only.
Summary
Set the local anchor point on fourth rigid body.
Syntax
constraint.setAnchorD(anchor);
Note
Available for constraint type Pulley only.
Summary
Get local axis point on first rigid body for line direction.
Syntax
var axis = constraint.getAxis();
// or
constraint.getAxis(axis);
Note
Available for constraint type Line only.
Summary
Set local axis point on first rigid body for line direction.
Syntax
constraint.setAxis(axis);
Note
Available for constraint type Line only.
Summary
Query the lower bound for constraint.
Syntax
var lowerBound = constraint.getLowerBound();
Note
Available for constraint types: Distance, Angle, Line, Pulley only.
Summary
Set the lower bound on constraint.
Syntax
constraint.setLowerBound(lowerBound);
Note
Available for constraint types: Distance, Angle, Line, Pulley only.
Summary
Query the upper bound for constraint.,
Syntax
var upperBound = constraint.getUpperBound();
Note
Available for constraint types: Distance, Angle, Line, Pulley only.
Summary
Set the upper bound on constraint.
Syntax
constraint.setUpperBound(upperBound);
Note
Available for constraint types: Distance, Angle, Line, Pulley only.
Summary
Query the current ratio parameter on constraint.
Syntax
var ratio = constraint.getRatio();
Note
Available for constraint types: Angle, Motor, Pulley only.
Summary
Set the ratio parameter on constraint.
Syntax
constraint.setRatio(ratio);
Note
Available for constraint types: Angle, Motor, Pulley only.
Summary
Query the current motor rate parameter on constraint.
Syntax
var rate = constraint.getRate();
Note
Available for constraint type Motor only.
Summary
Set the motor rate parameter on constraint.
Syntax
constraint.setRate(rate);
Note
Available for constraint type Motor only.
Summary
Query the current angular phase parameter on constraint.
Syntax
var phase = constraint.getPhase();
Note
Available for constraint type Weld only.
Summary
Set the angular phase parameter on constraint.
Syntax
constraint.setPhase(phase);
Note
Available for constraint type Weld only.
A string identifying the type of this Constraint object, one of:
Note
Read Only
Summary
The current World object that this constraint is assigned to.
Note
Read Only
Summary
Whether this constraint object is currently sleeping in an ongoing simulation.
Note
Read Only
Summary
The first RigidBody associated with this constraint.
Note
Read Only. Not defined for constraint type Custom.
Summary
The second RigidBody associated with this constraint.
Note
Read Only. Not defined for constraint type Custom.
Summary
The third RigidBody associated with this constraint.
Note
Read Only. Defined only for constraint type Pulley.