Sub topic 16
Blending FK and IK with Influence and Drivers
This chapter assumes you can pose bones in Pose Mode and add bone constraints. It also assumes you know how the IK constraint and a pole target work, and that you can read short Python scripts. You will build a switch that blends an arm between its FK pose and its IK pose, and you will learn why the blend behaves the way it does.
Why Switch Between FK and IK
FK (forward kinematics) means you rotate each bone yourself. The child bones follow their parents. FK is good for swinging arms and for arcs that follow through. IK (inverse kinematics) means you place a target and the solver rotates the chain to reach it. IK is good for a hand that must stay planted on a table or a wall.
Animators often need both in one shot. A character swings an arm freely (FK), then presses a hand on a surface (IK), then lets go (FK). A switch lets one rig do both without rebuilding it.
How the Blend Works
Every constraint has an influence value from 0.0 to 1.0. At 0.0 the constraint has no effect. At 1.0 it applies fully. Values in between mix the constrained result with the result the bone would have without the constraint.
For an IK constraint, the bone's own rotation (the FK pose you set with the rotate tool) is what you get at influence 0. The solver's result is what you get at influence 1. So the influence of the IK constraint on the last bone of the chain is already an FK/IK blend. You only need a convenient way to set it.
The influence of a constraint is a normal animatable property. That means you can:
- set it by hand in the Bone Constraints tab,
- keyframe it,
- drive it from another property with a driver.
A driver is a small expression or link that computes a property's value from other values. A driver on influence lets you control the blend from a custom property on a control bone, so the animator sees one slider and one keyframe track.
Setting Up the Arm
The examples use the arm from the earlier chapter on control rigs. The rig has bones upper_arm, forearm, hand_ik and elbow_pole, and an IK constraint on forearm that targets hand_ik with a pole on elbow_pole. If you need to rebuild it, this script creates the bones and the IK constraint together.
import math
import bpy
arm_data = bpy.data.armatures.new("ArmRig")
rig = bpy.data.objects.new("ArmRig", arm_data)
bpy.context.collection.objects.link(rig)
bpy.context.view_layer.objects.active = rig
rig.select_set(True)
bpy.ops.object.mode_set(mode='EDIT')
eb = arm_data.edit_bones
upper = eb.new("upper_arm")
upper.head = (0.0, 0.0, 0.0)
upper.tail = (1.0, 0.1, 0.0)
fore = eb.new("forearm")
fore.head = (1.0, 0.1, 0.0)
fore.tail = (2.0, 0.0, 0.0)
fore.parent = upper
fore.use_connect = True
hand_ik = eb.new("hand_ik")
hand_ik.head = (2.0, 0.0, 0.0)
hand_ik.tail = (2.0, 0.0, 0.3)
elbow_pole = eb.new("elbow_pole")
elbow_pole.head = (1.0, 2.0, 0.0)
elbow_pole.tail = (1.0, 2.0, 0.3)
bpy.ops.object.mode_set(mode='POSE')
forearm = rig.pose.bones["forearm"]
ik = forearm.constraints.new('IK')
ik.target = rig
ik.subtarget = "hand_ik"
ik.pole_target = rig
ik.pole_subtarget = "elbow_pole"
ik.pole_angle = math.radians(-90.0)
ik.chain_count = 2With this rig, upper_arm and forearm are the FK bones. You rotate them directly when the IK constraint is off. hand_ik and elbow_pole are the IK controls. They only matter when the constraint has influence.
Adding the Switch Property
A custom property is a named value stored on a bone or object. Put the switch on hand_ik, because that is the bone the animator selects to use IK.
import bpy
rig = bpy.data.objects["ArmRig"]
hand_ik = rig.pose.bones["hand_ik"]
hand_ik["ik_switch"] = 1.0
hand_ik.id_properties_ui("ik_switch").update(min=0.0, max=1.0, soft_min=0.0, soft_max=1.0)The id_properties_ui call sets the slider range. Without it the property accepts any number, and a value above 1.0 will confuse the animator. Note that the driver will still pass the raw number to influence, which Blender then clamps to its own range of 0 to 1.
Driving the Influence
Now add the driver to the IK constraint. This is the same setup as the topic's driver example.
import bpy
rig = bpy.data.objects["ArmRig"]
forearm = rig.pose.bones["forearm"]
hand_ik = rig.pose.bones["hand_ik"]
hand_ik["ik_switch"] = 1.0
ik = forearm.constraints["IK"]
fcurve = ik.driver_add("influence")
driver = fcurve.driver
driver.type = 'AVERAGE'
var = driver.variables.new()
var.name = "switch"
var.type = 'SINGLE_PROP'
var.targets[0].id = rig
var.targets[0].data_path = 'pose.bones["hand_ik"]["ik_switch"]'Three details matter here.
driver.type = 'AVERAGE'returns the average of its variables. With one variable, the result is that variable's value, so no expression is needed.var.targets[0].idmust be the armature object, not the armature data. The data path starts from the object, which is why it begins withpose.bones.- The data path uses the bone's name in quotes. If you rename
hand_iklater, Blender updates many references, but a driver written as a script string can break. Check the driver in the Drivers editor after any rename.
You can also write the driver with an expression instead. Setting driver.type = 'SCRIPTED' and driver.expression = "switch" gives the same result, and lets you reshape the value later, for example "switch * switch" for a slower start.
What You See at Each Value
The blend is not a spatial interpolation between two joint angles. Blender evaluates the pose both ways and mixes the results at the matrix level, so values in between can look slightly odd.
| `ik_switch` | Result |
|---|---|
| 1.0 | The solver places the hand on `hand_ik`. FK rotations on the chain are ignored. |
| 0.5 | A mix of the IK result and the FK pose. The hand is usually off the target. |
| 0.0 | The FK pose only. Moving `hand_ik` has no effect on the arm. |
Use 0.0 and 1.0 for animation. Use values in between only to ease a transition over a few frames.
Matching the Two Poses Before You Switch
Switching changes the pose instantly if the FK pose and the IK pose differ. The arm jumps. To avoid a pop, make the two poses agree on the frame where you switch:
- Set
ik_switchto 1.0 and place the hand where you want it. - Keyframe
ik_switchat the switch frame, then set it to 0.0 on the next frame. - On the switch frame, copy the IK result into the FK rotations, so the FK pose matches. In Pose Mode, you can apply the visual transform (Pose > Apply > Visual Transform) to bake the constrained result into the bone's own rotation. Do this for each FK bone.
Doing this by hand for every switch is slow. Production rigs add scripted snapping buttons. For a small rig, a short script is enough.
import bpy
rig = bpy.data.objects["ArmRig"]
bpy.context.view_layer.objects.active = rig
bpy.ops.object.mode_set(mode='POSE')
for bone in rig.pose.bones:
bone.bone.select = bone.name in {"upper_arm", "forearm"}
bpy.ops.pose.visual_transform_apply()Run it with ik_switch at 1.0, then set the property to 0.0. The FK bones now hold the pose the solver produced, so the arm stays where it was.
Common Problems
- The slider does nothing. The driver may be invalid. A driver with an error shows a red field in the Bone Constraints tab. Open the Drivers editor and read the error message beside the driver.
- The arm does not move at 0.0. That is correct. At 0.0 the FK rotations decide the pose. Rotate
upper_armandforearmto see it respond. - Keyframes fight the driver. A property cannot be both keyframed and driven. Keyframe
ik_switchonhand_ik, and let the driver pass that value toinfluence. - The elbow jumps when you switch. The two poses did not match. Use the matching steps above.
- The hand drifts at 0.5. This is expected, because two different poses are being mixed.
Exercise
Why do you keyframe the ik_switch custom property on hand_ik instead of keyframing the IK constraint's influence directly once a driver is attached?
Show answer
A driver controls the influence property, and a property that is driven cannot also hold its own keyframes. Keyframing the custom property that feeds the driver gives the animator one control to key, and the driver passes the value to the constraint.
Exercise
The arm is in the IK pose at ik_switch = 1.0. You set the property to 0.0 and the arm jumps to a different pose. What is the cause, and what do you do before switching next time?
Show answer
At 0.0 the pose comes from the FK bones' own rotations, which were never matched to the IK result. Before switching, apply the visual transform of the IK result to upper_arm and forearm (Pose > Apply > Visual Transform), then set the property to 0.0.