Skip to content
Chandler edited this page Jul 12, 2015 · 2 revisions

Constraints are used to constrain linear and/or angular velocity between an object and the world or between two objects. When constraining motion for a single body instead of a two-body pair, omit the object_b parameters found in the below examples. Constraint details involving positions & vectors are given relative to the objects themselves, not in world coordinates.

Every constraint has these base properties:

  • factor a scalar value 0.0 - 1.0 (default 1.0) used to scale back a constraint, lower values create softer constraints
  • last_impulse a Vector3 specifying how much work this constraint had to perform in the last simulation step
  • breaking_threshold a scalar value (default 0.0) that when > 0.0 specifies how much force a constraint may exert before breaking (disabling itself)

In addition, if a constraint has a breaking_threshold and "breaks" during the course of the simulation, the constraint will fire a deactivate event:

constraint.addListener(
	'deactivate',
	function() {
		// the constraint's breaking_threshold was reached and the constraint has been deactivated
	}
);

Point Constraint

The PointConstraint restricts an object's linear motion at a point but allows angular motion. An example use is a trailer hitch, where a vehicle and trailer are connected at a point that freely allows rotation.

constraint = new Goblin.PointConstraint(
	object_a,
	constraint_point_a, // Vector3 constraint point in the first object, ignoring its position & rotation
	object_b, // [optional]
	constraint_point_b // [optional] Vector3 constraint point in the second object, ignoring its position & rotation
);
world.addConstraint( constraint );

Hinge Constraint

A HingeConstraint attaches an object to the world (or two objects together) as a hinge, allowing only angular motion along a single axis.

constraint = new Goblin.HingeConstraint(
	object_a,
	hinge_axis, // Vector3 normalized axis of allowed rotation in object_a's coordinates
	constraint_point_a, // point in object_a that is the hinge
	object_b, // [optional]
	constraint_point_b // [optional] point in object_b that is the hinge
);
world.addConstraint( constraint );

Slider Constraint

The SliderConstraint removes all angular motion and restricts linear motion to a single axis.

var constraint = new Goblin.SliderConstraint(
	object_a,
	slider_axis, // axis, in object_a's coordinates, of allowed motion
	object_b // [optional]
);
world.addConstraint( constraint );

Weld Constraint

Creating a WeldConstraint will restrict all linear & angular motion.

var constraint = new Goblin.WeldConstraint(
	object_a,
	constraint_point_a, // point in object_a that is the weld
	object_b, // [optional]
	constraint_point_b // [optional] point in object_b that is the weld
);
world.addConstraint( constraint );
Clone this wiki locally