Sub topic 11
Limit Rotation, Location, and Distance Constraints
This chapter assumes you can add a constraint to a pose bone, that you know the stack and influence model from the earlier constraint chapters, and that you understand owner and target spaces. The scripts use the ArmRig from the arm-building example and a little Python.
What Limit Constraints Do
A limit constraint does not move a bone toward anything. It takes the transform the bone already has and clamps part of it. The input might come from your hand, from keyframes, from the IK solver, or from constraints above it in the stack. Because it only clamps, a limit constraint is a safety rail on a rig. It keeps a control bone above the floor, keeps an elbow from bending backward, and keeps an IK target within reach of the arm.
| Constraint | What it clamps | Key options | Typical use |
|---|---|---|---|
| Limit Rotation | Euler rotation per axis | `use_limit_x/y/z`, `min_*`, `max_*`, `owner_space` | Hinge joints, neck and spine range |
| Limit Location | Position per axis | `use_min_*`, `use_max_*`, `min_*`, `max_*` | Floor planes, sliders, control bounds |
| Limit Distance | Distance to a target | `distance`, `limit_mode`, `head_tail` | Reach limits, tethers, keeping a point on a sphere |
Limit Rotation
Limit Rotation compares the bone's rotation, expressed as Euler angles, against a minimum and maximum for each enabled axis. The values are in radians in Python and in degrees in the interface.
Three details cause most mistakes:
- Space. For a bone, set the owner space to Local Space. The limits then apply to the bone's rotation relative to its rest pose and parent, which matches how you think about a joint. In World Space the limits describe the bone's absolute orientation. That is rarely what you want for a joint that moves around.
- Defaults. When you enable an axis, its minimum and maximum are both 0, so the axis is pinned. This is useful for locking an axis. It also makes a freshly enabled limit look like it broke the bone.
- Euler conversion. The constraint works on Euler angles even if the bone uses quaternions. Narrow ranges on one axis behave well. Wide ranges on several axes can behave oddly near gimbal configurations, because the Euler decomposition jumps. Recent Blender versions let you choose the Euler order on the constraint. Pick an order in which the axis with the widest range comes last.
The Affect Transform option (use_transform_limit) matters for animators. When it is off, the viewport can still rotate the bone past the limit, and only the final evaluated pose is clamped. That looks like a bone ignoring your drag. When it is on, interactive rotation is clamped too, and the manipulator stops at the limit.
import math
import bpy
rig = bpy.data.objects["ArmRig"]
forearm = rig.pose.bones["forearm"]
limit = forearm.constraints.new('LIMIT_ROTATION')
limit.name = "Elbow Hinge Limit"
limit.owner_space = 'LOCAL'
limit.use_limit_x = True
limit.min_x = 0.0
limit.max_x = math.radians(150.0)
limit.use_limit_y = True # min and max stay 0, so Y is held at zero
limit.use_limit_z = True # same for Z
limit.use_transform_limit = True # also clamp interactive rotationLimit Rotation Versus IK Limits
IK limits and a Limit Rotation constraint look like they do the same job on an IK bone, but they work differently:
- Per-bone IK limits are read by the IK solver. The solver knows the elbow cannot bend past 150 degrees and searches for a pose that reaches the target within that range.
- A Limit Rotation constraint is applied to the pose after the solver has finished. The solver does not know about it. If the solved pose violates the limit, the constraint pulls the bone back, and the hand then misses the target.
Use IK limits to shape how the chain solves. Use Limit Rotation as a final guard that also catches FK posing and other sources. The two can be combined with the same range on a bone.
Limit Location
Limit Location clamps the bone's position. Each axis has a separate lower and upper switch, so you can set a floor without setting a ceiling. As with rotation, space decides the meaning. A World Space limit with min_z = 0 is a floor plane. A Local Space limit is relative to the bone's rest position and parent. This suits sliders such as a jaw or a piston that moves along one axis.
import bpy
rig = bpy.data.objects["ArmRig"]
hand = rig.pose.bones["hand_ik"]
floor = hand.constraints.new('LIMIT_LOCATION')
floor.name = "Floor"
floor.owner_space = 'WORLD'
floor.use_min_z = True
floor.min_z = 0.0
floor.use_transform_limit = TrueIf the rig object itself is moved or rotated, "World" here still means the scene's world, not the rig's frame. When the whole rig must carry its floor with it, use Pose Space or Local Space instead.
Limit Distance
Limit Distance keeps the owner within a set distance of a target. It has three modes:
- Clamp Inside keeps the owner within the radius. It is free inside the sphere and held on the surface when it tries to leave.
- Clamp Outside keeps the owner out of the sphere. This is the sphere-collision case.
- Limit On Surface holds the owner exactly at the distance.
A distance of 0 is a special value. On the first evaluation, Blender replaces it with the current distance between owner and target. If you create the constraint in a script and then move bones, the stored distance is whatever the bones were apart at that first evaluation. Set distance explicitly in scripts. In the interface, the Reset Distance button redoes the capture.
The most useful rig application is stopping an IK target from leaving the arm's reach. An IK chain that cannot reach its target straightens fully and then stops, so the hand control and the real hand drift apart. Limiting the control's distance from the shoulder keeps them together.
import bpy
rig = bpy.data.objects["ArmRig"]
hand = rig.pose.bones["hand_ik"]
reach = hand.constraints.new('LIMIT_DISTANCE')
reach.name = "Max Reach"
reach.target = rig # no subtarget: measures from the rig object origin
reach.limit_mode = 'LIMITDIST_INSIDE'
reach.distance = 2.0 # slightly under the arm length of about 2.005
reach.owner_space = 'WORLD'
reach.target_space = 'WORLD'
reach.use_transform_limit = TrueOrder and Influence
Constraints evaluate from the top of the stack to the bottom, and each one receives the result of the one above. A limit therefore only affects what is above it.
Influence blends the clamped result with the unclamped input. At an influence of 0.5, a bone 40 degrees past the limit ends up about 20 degrees past it. That makes influence useful for soft limits, and it is a common reason a limit seems weak.
Common Problems
- The limit has no visible effect. Check that it is below the constraint that produces the motion, that the axis switch is enabled, and that the space is the one you intended.
- The bone snaps to a strange pose. An enabled axis with 0 for both minimum and maximum pins it. Set the range, or turn that axis off.
- A hand control drifts from the hand. Add Limit Distance to the control. A limit on the final bone only hides the problem.
- The viewport ignores the limit while dragging. Enable Affect Transform.
Exercise
A Limit Rotation constraint on forearm is listed above the IK constraint in the stack. The elbow still bends beyond the limit. Why, and what are two ways to fix it?
Show answer
Constraints evaluate top to bottom, so the limit clamps the pose before IK runs, and the IK solver then overwrites the rotation. Fix it by moving the Limit Rotation below the IK constraint, so it clamps the solved result. Or set per-bone IK limits on the forearm (use_ik_limit_x, ik_min_x, ik_max_x), so the solver respects the range itself. Doing both is also reasonable.
Exercise
You create a Limit Distance constraint in a script without setting distance, after you have already moved the owner bone far from the target. What distance does the constraint use, and how do you avoid surprises?
Show answer
A distance of 0 is replaced with the current owner-to-target distance on the first evaluation, so the constraint locks in whatever separation exists at that moment. Avoid this by assigning an explicit distance value in the script, or by using the Reset Distance button after placing the bones in the interface.