Sub topic 11
Bone constraints
This chapter assumes you can move between Object, Edit and Pose modes, pose a bone with forward kinematics, and read a bone hierarchy. It also assumes you know the rest pose from the pose. You do not need inverse kinematics yet. IK is a special constraint, and the next chapter covers it.
What a bone constraint is
A constraint is a rule attached to a bone that overrides or limits its transform. You can copy another bone's rotation, stop an elbow from bending backward, or make a bone always point at a target. The rule is evaluated every time the scene updates, so you do not have to keep the bone in place by hand.
Constraints live on pose bones, not on edit bones or on the armature data. They belong to the armature object, as posing does. They never change the rest pose. They only change the final pose, which you can see in the viewport and which deforms the mesh.
In the interface, select the armature, enter Pose Mode, select a bone, and open the Bone Constraints tab in the Properties editor. Do not confuse it with the Object Constraints tab. Adding a constraint there affects the whole armature object.
How constraints are evaluated
A pose bone's final transform is built in a fixed order:
- Blender takes the rest pose and the parent chain.
- It applies the bone's own pose transform (location, rotation, scale), including any keyframes.
- It runs the constraint stack from top to bottom.
Each constraint receives the result of the one above it. Order therefore matters. A Limit Rotation placed before a Copy Rotation does nothing useful, because the copy overwrites the limited value. Put limits last unless you want the opposite.
Targets, spaces and influence
Most constraints have the same three settings.
Target. The constraint reads from another object. If the target is an armature object, a Bone field appears. In Python these are target and subtarget. A bone can target a bone in the same armature, a bone in a different armature, or an empty.
Spaces. A transform can be read and written in several coordinate systems. Each has an owner space (the bone being constrained) and a target space (the thing it follows).
| Space | Meaning | Typical use |
|---|---|---|
| World Space | Relative to the scene origin | Following an empty |
| Local Space | Relative to the bone's rest pose, ignoring the parent | Copying a bend between bones, limiting a joint |
| Local with Parent | Local, plus the parent's rest orientation | Mixed cases in some rigs |
| Pose Space | Relative to the armature object | Matching a bone's position in the rig |
Local Space is the one to use for joint limits, because the limit then follows the bone when its parent moves.
Influence. A value from 0 to 1 that blends the constraint's result with the result before it. At 0 the constraint does nothing. Influence can be keyframed, which is how a rig switches a hand between "free" and "holding a prop".
Constraints you will use most
| Constraint | What it does | Common use |
|---|---|---|
| Copy Location / Rotation / Scale | Matches one transform of the target | Helper bones, twist bones |
| Limit Rotation | Clamps rotation per axis | Knees, elbows, fingers |
| Damped Track | Points one bone axis at a target | Eyes, aiming |
| Track To | Like Damped Track, with an up axis | Cameras, head look-at |
| Stretch To | Stretches a bone toward a target | Squash and stretch limbs |
| Child Of | Parents a bone to a target at runtime | Hand grabbing a prop |
| Inverse Kinematics | Solves a chain to reach a target | Legs, arms (next chapter) |
Child Of is the one most people trip over. It has an inverse matrix that records the offset when you set the parent. If the bone jumps when you add it, use Set Inverse.
Adding constraints with Python
The script below builds a two-bone armature, then constrains the follower bone to copy half of the driver bone's rotation and to limit its own X rotation to 0–90 degrees. It runs from the Scripting workspace.
import bpy
import math
# Create the armature object
arm_data = bpy.data.armatures.new("ConstraintDemo")
arm_obj = bpy.data.objects.new("ConstraintRig", arm_data)
bpy.context.collection.objects.link(arm_obj)
bpy.context.view_layer.objects.active = arm_obj
# Edit bones can only be created in Edit Mode
bpy.ops.object.mode_set(mode='EDIT')
driver = arm_data.edit_bones.new("driver")
driver.head = (0, 0, 0)
driver.tail = (0, 0, 1)
follower = arm_data.edit_bones.new("follower")
follower.head = (1, 0, 0)
follower.tail = (1, 0, 1)
bpy.ops.object.mode_set(mode='OBJECT')
# Constraints are added to pose bones
pbone = arm_obj.pose.bones["follower"]
copy = pbone.constraints.new('COPY_ROTATION')
copy.name = "Follow driver"
copy.target = arm_obj
copy.subtarget = "driver"
copy.target_space = 'LOCAL'
copy.owner_space = 'LOCAL'
copy.influence = 0.5
limit = pbone.constraints.new('LIMIT_ROTATION')
limit.name = "Limit bend"
limit.use_limit_x = True
limit.min_x = 0.0
limit.max_x = math.radians(90)
limit.owner_space = 'LOCAL'
# Pose the driver and watch the follower react
driver_pose = arm_obj.pose.bones["driver"]
driver_pose.rotation_mode = 'XYZ'
driver_pose.rotation_euler = (math.radians(60), 0, 0)Switch to Pose Mode and select driver. Rotating it around X turns follower by about half as much. Angles in the API are radians, so math.radians is needed for max_x.
Constraints appear in pbone.constraints in stack order. To change the order in the interface, drag the constraint's grip handle. In Python, call pbone.constraints.move(from_index, to_index).
Common errors
- The constraint does nothing. The most common causes are an empty target field, an empty Bone field when the target is an armature, or an influence of 0. A red constraint header means the target is invalid.
- The bone flips or jumps. Spaces probably do not match. Try Local Space on both sides, or use Set Inverse for Child Of.
- A limit seems ignored. Another constraint below it overwrites the value, or the bone is also driven by IK. Move the limit down the stack. IK has its own limit settings in the bone's Inverse Kinematics panel.
- Constraints affect the wrong thing. You added them in the Object Constraints tab, not the Bone Constraints tab.
- Dependency cycles. Bone A copying from bone B while B copies from A produces a cycle. Blender stops evaluating it and the bones stay still. Break the loop by removing one of the links.
- Applying a pose bakes the constraint. Pose > Apply > Apply Pose as Rest Pose changes the rest pose permanently. Use it deliberately, not to "fix" a constraint.
Exercise
A bone has a Copy Rotation constraint followed by a Limit Rotation constraint, and the limit seems to have no effect on the copied rotation. A teammate swaps the order and it works. Why?
Show answer
Constraints run from top to bottom, and each one receives the result of the one above it. With the order Limit then Copy, the Copy Rotation overwrites the already-limited value, so the limit is lost. With Copy first and Limit second, the limit clamps the copied rotation, which is the intended behavior.
Exercise
You script a bone constraint on arm_obj.pose.bones["follower"] and set copy.target = arm_obj. The constraint shows no effect. Which property is likely missing?
Show answer
copy.subtarget must be set to the name of a bone (for example "driver"). When the target is an armature object, an empty Bone field means the constraint has no specific bone to read from, so it has nothing to copy.