Skip to content

Constraints

Marc Flerackers edited this page Aug 30, 2025 · 9 revisions

Currently there are the following constraints:

  • Translation: Constraints the translation of the object to that of the target.
  • Rotation: Constraints the rotation of the object to that of the target.
  • Scale: Constraints the scale of the object to that of the target.
  • Transform: Constraints the transform of the object to that of the target.
  • Distance: Constraints the distance between the object and the target.

These constraints all work in world space. For example, distance is measured in world space, not local space. So even if an object scales times 2, a distance of 200 pixels is still 200 pixels in world space, not 200 pixels in local space, which would be 400 pixels in world space.

In progress:

  • IK constraint

Planned:

  • Path constraint

IK constraint

Nomenclature:

  • Root: The start of the IK chain
  • End effector: The end of the IK chain, which tries to reach the target.
  • Target: The point for the end effector to reach.
constraint.ik(target, { 
  algorithm: "ccd",
  depth: 2, 
  strength: 1
});

Parameters:

  • algorithm:
    • FABRIK (Forward And Backward Reaching Inverse Kinematics): Fast, but unable to use angle constraints.
    • CCD (Cyclic Coordinate Descent): Slower, but can use angle constraints.
  • depth: Defines the actual IK chain. A depth of 2 means that the chain root is two parents from the end effector.

Angle constraints can be set (if using CCD) using a bone component.

bone({ minAngle: -180, maxAngle: 180 });

Path constraint

constraint.path(path, {
  distance: 0,
  offset: vec2(50, 50),
  followMotion: true,
  strength: 1
});

Clone this wiki locally