Loading lessons...
Inverse Kinematics (IK) & Retargeting
Inverse Kinematics (IK) & Retargeting
For humanoid characters, Unity includes advanced tools to adjust animations to match physical environments.
Animator Retargeting
Retargeting is the ability to share animations between different humanoid 3D models.
- Set the Rig Type on both models to Humanoid in the import settings.
- Unity maps both models' skeletons to a standard avatar profile.
- You can then use the same Animator Controller and clips on both characters, regardless of bone size differences.
Inverse Kinematics (IK)
Standard animations use Forward Kinematics (FK): rotation values propagate down the skeleton (e.g. rotating the shoulder moves the elbow, which moves the hand).
Inverse Kinematics (IK) works in reverse: you define a target position (e.g., a coffee cup), and Unity calculates the rotations of the elbow and shoulder to place the hand exactly at that position.
IK Scripts in Unity:
To use IK, check IK Pass in your Animator Controller layer settings:
void OnAnimatorIK(int layerIndex)
{
// Enable and set hand IK target
anim.SetIKPositionWeight(AvatarIKGoal.RightHand, 1.0f);
anim.SetIKRotationWeight(AvatarIKGoal.RightHand, 1.0f);
anim.SetIKPosition(AvatarIKGoal.RightHand, lookTarget.position);
}
Common goals include placing feet flat on uneven terrain or making a character look toward an object.
TL;DR
- Humanoid Rig settings enable animator retargeting between skeletons.
- Forward Kinematics rotates bones; Inverse Kinematics targets endpoints.
- Check the 'IK Pass' option on the animator layer settings to enable IK callbacks.
- Implement
OnAnimatorIKin scripts to set goal positions and weights.