Sub topic 16
Blending FK and IK with Influence and Drivers
This chapter assumes that you can create an armature, switch modes, add bone constraints, and set basic keyframes. It also assumes that your rig already has an FK control and an IK target. FK, or forward kinematics, rotates each bone directly. IK, or inverse kinematics, moves a target and lets Blender solve the connected bones.
A switch is useful when an animator wants both workflows. For example, an arm can use IK while a hand holds a prop, then switch to FK for a carefully animated arc. Constraint influence controls how strongly a constraint affects its owner. An influence of 0 disables the constraint. An influence of 1 applies it fully. A driver is a rule that calculates a property from another property.
Drive IK influence from a custom property
Add a custom property named ik_switch to an IK control bone. Use 0 for FK and 1 for IK. Then connect that property to the IK constraint's influence.
import bpy
rig = bpy.data.objects["ArmRig"]
forearm = rig.pose.bones["forearm"]
hand_ik = rig.pose.bones["hand_ik"]
# The animator changes this value in the control bone's custom properties.
hand_ik["ik_switch"] = 1.0
ik = forearm.constraints.get("IK")
if ik is None:
ik = forearm.constraints.new(type="IK")
ik.name = "IK"
fcurve = ik.driver_add("influence")
driver = fcurve.driver
driver.type = "SCRIPTED"
driver.expression = "max(0.0, min(1.0, switch))"
variable = driver.variables.new()
variable.name = "switch"
variable.type = "SINGLE_PROP"
variable.targets[0].id = rig
variable.targets[0].data_path = 'pose.bones["hand_ik"]["ik_switch"]'The expression clamps the value to the valid range. Values below 0 become 0, and values above 1 become 1.
A complete FK/IK setup usually drives two constraints:
- The IK constraint uses
ik_switch. - The FK constraint uses
1 - ik_switch.
At 0, the FK constraint has full influence and the IK constraint has none. At 1, the reverse is true. Intermediate values blend both results, but the blend is not automatically a perfect pose match.
Keep the switch visually stable
Before changing the switch, align the inactive controls to the current pose. To switch from FK to IK, place the IK target at the hand's current position and rotate it to match the hand. To switch from IK to FK, match the FK control rotations to the current solved pose.
Keyframe both the custom property and the relevant control transforms on the same frame. If the controls are not aligned, the arm can pop when influence changes.
Exercise
Exercise
Why can an arm pop when the IK switch changes from 0 to 1, even if both constraints have been set up correctly?
Show answer
The FK and IK controls may describe different poses. Match the inactive control to the current pose before changing and keyframing the switch.