Animation Rigging — Procedural Animation and IK
TwoBone IK, Aim Constraint, Multi-Parent — layering procedural layers over a ready-made animation.
The standard Animator plays back recorded animations. What do you do if:
- The character needs to look at a dynamic target (an enemy, the mouse cursor).
- A hand needs to hold a door handle while it turns.
- A foot needs to touch uneven ground correctly (foot IK).
The Animation Rigging package (com.unity.animation.rigging) provides procedural constraints
that are applied on top of the Animator’s regular animation.
The main idea — a riggable layer
Structure:
Player (Animator)
└── Hips (root bone)
├── Spine → Chest → Neck → Head
├── LeftShoulder → ...
└── RightShoulder → ...
Player → RigBuilder (component)
└── Rig (GameObject)
└── HeadAimConstraint (node)
constrained_object: Head
source_objects: [Target]
weight: 1.0
RigBuilder collects all constraints and applies them after the Animator’s base animation. The
constraints are separate GameObjects with a logic component.
Animation pipelines like Three.js + an IK solver, or spline-based rigging in Blender. Only in Unity this is runtime, real-time, every frame.
Animation Rigging doesn’t replace the Animator — it complements it. The Animator says “the right hand is here”, and Rigging says “and we bring it to the target”. Weights let you blend the procedural with the recorded.
Installation
- Package Manager → Animation Rigging → Install.
- On the GameObject with the Animator → Add Component → Rig Builder.
- As a child of it — an Empty GameObject “Rig” → add the Rig component.
- In Rig Builder, specify “Rig” in the Layers list.
- Add constraint nodes to the Rig as children.
TwoBone IK — the hand reaches a point
The most common IK. The goal is to specify “where the hand reaches”, and the solver finds the elbow’s position.
- On the Rig, add an Empty GameObject “RightArmIK”.
- Add Component → Two Bone IK Constraint.
- In the Inspector:
- Root: the right shoulder bone
- Mid: the right elbow bone
- Tip: the right hand bone
- Target: an empty object (where the hand reaches)
- Hint: an empty object (the direction toward the elbow — so the solver knows “which way to bend”)
You move the Target — the hand automatically reaches it, and the elbow bends naturally.
public class GrabHandle : MonoBehaviour
{
[SerializeField] private Transform ikTarget;
[SerializeField] private TwoBoneIKConstraint armIK;
public void GrabAt(Transform doorHandle) {
ikTarget.position = doorHandle.position;
ikTarget.rotation = doorHandle.rotation;
StartCoroutine(BlendWeight(0f, 1f, 0.3f)); // turn it on smoothly
}
private IEnumerator BlendWeight(float from, float to, float duration) {
float t = 0;
while (t < duration) {
t += Time.deltaTime;
armIK.weight = Mathf.Lerp(from, to, t / duration);
yield return null;
}
armIK.weight = to;
}
}
weight = 1.0 — IK is fully active. weight = 0 — the original Animator animation. Between 0 and 1
it’s a blend. This gives a smooth “grab the handle” animation.
Aim Constraint — look at a target
The character’s head tracks the target:
- On the Rig, add “HeadAim”.
- Multi-Aim Constraint.
- Constrained Object: the Head bone.
- Source Objects: an array with one target (or several with weights).
- Aim Axis: usually forward Z.
- World Up Type: ObjectRotationUp → object: Head (so the head doesn’t “flip over”).
- Limits: ±60° (you can’t turn the head 180° — it’s not an owl).
[SerializeField] private MultiAimConstraint headAim;
[SerializeField] private Transform aimTarget;
private void Update() {
// The target = the mouse cursor via a raycast
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hit, 50f)) {
aimTarget.position = hit.point;
}
}
Now the character’s head tracks the cursor in real time, without a recorded “turn the head toward the point” animation.
Multi-Parent Constraint — two hands on one object
Scenario: the character carries a sword with both hands. The walk animation is authored for one hand; the other needs to be procedurally held on the grip.
- On the Rig → “LeftHandToSword”.
- Multi-Parent Constraint.
- Constrained Object: the left hand bone.
- Source Objects: [SwordHandle_Left] (a target on the sword where the left palm should be).
- Constrained Properties: Position + Rotation.
Now wherever the right hand (with the sword) moves, the left always “sticks” to the right point on the sword.
Chain IK — for long chains (a tail, a tentacle)
TwoBoneIKConstraint handles 3 bones. For a long chain (4+):
- Chain IK Constraint — for an arbitrary number of bones. The FABRIK algorithm.
Use: tentacles, tails, flexible animals.
Override Transform — full control of one bone
If you need to fully control the position/rotation of a specific bone, bypassing the Animator:
- Override Transform Constraint.
- The source is a Transform object in the scene.
- The target bone fully copies its transform.
Useful for:
- Attaching a weapon to a hand bone (or use the Bone Attachment pattern with a child GameObject).
- “Freezing” a bone in a specific position.
Damped Transform — delay / “spring”
A constraint where a bone catches up to the target with a delay:
- Damped Transform Constraint.
- Damp Position / Damp Rotation — how much it lags behind.
Use: earrings, dangling accessories, long hair.
Performance
Each constraint is per-frame compute. Dozens of constraints on a single character can cost noticeably. Profile it.
Especially expensive:
- Multi-Aim with a large number of source objects.
- Chain IK with a long chain.
- Override Transform on every bone.
Optimization: set RigBuilder.enabled = false for off-screen / distant characters.
Workflow: blending the ready-made and the procedural
The classic approach:
1. The Animator plays a Walk-Run blend tree → the base pose.
2. Rig Builder applies:
- Head Aim → the head toward the enemy
- Left Hand IK → the palm on the weapon (if it's two-handed)
- Foot IK → the feet stand correctly on the stairs
3. The final pose is rendered.
The player sees: the character naturally walks through the scene, looks at the enemy, and climbs the stairs placing the feet correctly — without 50 recorded animations for different geometry.
The Animator (Humanoid) has a built-in OnAnimatorIK callback with SetIKPosition/SetIKWeight —
enough for basic Foot IK. Animation Rigging is needed if you want a more custom workflow or a
non-humanoid skeleton (for example, creatures with 4 legs).
When Animation Rigging is not needed
- If all the movements you need are already in a recorded animation — don’t add an extra component.
- For mass NPCs in an open world — it’s too expensive; use simplified Humanoid IK.
- In 2D projects — there you have the 2D Animation package and Sprite Skin.