-
-
Notifications
You must be signed in to change notification settings - Fork 108
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
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,
iterations:10,
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.
- iterations: The amount of iterations of the algorithm during one frame.
Angle constraints can be set (if using CCD) using a bone component. It can also be used to avoid drift of the bone length.
bone({
minAngle: -180,
maxAngle: 180,
length: 100
});constraint.path(target, {
distance: 0,
offset: vec2(50, 50),
followMotion: true,
strength: 1
});The target needs to have a path component.
Parameters:
- distance: Current normalized distance on the path, between 0 and 1.
- offset: The offset from the path.
- followMotion: If true, the angle of the object is adapted in order to orient itself according to the path motion.
- strength: How much the constraint impacts the position of the object, usually 1.
