Inverse Kinematics

The most common form of animation uses Forward Kinematics where each bone is given a specific rotation which it adds to the rotation of its parent. So you rotate the shoulder and the elbow moves accordingly because it is a child of the shoulder. You rotate the elbow and the hand moves accordingly. And so on.

But sometimes it is desirable to directly control the end point instead. With Inverse Kinematics, you specify the desired position of a hand or foot and the IK system figures out how to rotate the bones to get it there. This can be used to have a hand reach a specific point such as a door handle or adjusting the height of a foot to match the terrain.

Animancer allows you to use Unity's inbuilt Humanoid IK system in mostly the same way you would with Mecanim. The main difference is that you enable it by setting AnimancerLayer.ApplyFootIK or AnimancerLayer.ApplyAnimatorIK (or the same properties in a specific AnimancerState) instead of enabling it with toggles in an Animator Controller.

You can also enable/disable IK using the Context Menu Functions in the AnimancerComponent Inspector for testing purposes (the setting will not be stored in the scene or prefab, so you will always need to enable Ik with a script to use it at runtime).

The Inverse Kinematics examples demonstrate the use of this feature.

Foot IK

Foot IK allows Unity to make the character's feet more closely match the original animation's positions after retargeting it from the animation's rig to the model's rig. This can help reduce foot sliding caused by differing rig proportions, but it also often has undesirable results so it should be selected on a case by case basis.

void EnableFootIK(AnimancerComponent animancer, AnimationClip clip)
    var state = animancer.States.GetOrCreate(clip);
    state.ApplyFootIK = true;
    // Can also be set per-layer like below.

This is equivalent to the Foot IK toggle in an Animator Controller state:

Internally, when Unity creates an AnimationClipPlayable it actually starts with the Foot IK enabled by default. Unity Support says this is "by design" since they believe it looks better, however this default is not mentioned anywhere in the Unity Manual and many users complained about the foot pose being different from the original animation when using Animancer so it simply disables Foot IK when the playable is created (unless you set AnimancerLayer.DefaultApplyFootIK = true beforehand).

IK Pass

The IK Pass causes Unity to call the OnAnimatorIK(int layerIndex) method every frame in any scripts attached to the same object as the Animator.

void EnableIKPass(AnimancerComponent animancer, int layerIndex)
    animancer.Layers[layerIndex].ApplyAnimatorIK = true;
    // Can also be set per-state like above.

This is equivalent to the IK Pass toggle in an Animator Controller layer, except that due to limitations in the Playables API the layerIndex Unity passes into OnAnimatorIK will always be zero:

As outlined in the Unity Versions section, using the IK Pass with Animancer requires Unity 2018.1 or newer. However, 2018.3 is recommended because a bug in earlier versions prevented the OnAnimatorIK method from being called while fading between animations (specifically, it would only be called while at least one animation had its AnimancerNode.Weight == 1). This only applies to Unity's inbuilt IK Pass so other systems that do not use the OnAnimatorIK method will not have the same issue.

Exposed Curves

It is quite common to use an AnimationCurve in an AnimationClip to control the weight of the IK.

Normally to access a custom curve at runtime you would add a float parameter with the same name to your AnimatorController so that Unity will automatically update it and you can then read the value from that parameter to control the weight of the IK each frame. However, the Playables API has no such parameters, nor any similar method for evaluating an animation curve inside a clip (other than using a ControllerState to play an Animator Controller). You could simply store the AnimationCurve separately from the AnimationClip, but it is usually much easier to set up as part of the animation so that you can preview it as you configure the curve relative to the timing of the animation.

Animancer uses ExposedCurves to solve this problem by extracting a chosen curve from an AnimationClip in the Unity Editor and serializing it in the ExposedCurve so it can be evaluated at runtime:

  1. Create an ExposedCurve using Assets/Create/Animancer/Exposed Curve.
  2. Assign the AnimationClip containing the curve and enter the Property Name of the curve.
  3. Any future changes to the original curve in the AnimationClip will automatically be retrieved by the ExposedCurve. Unfortunately it is not currently possible to edit the curve using the ExposedCurve Inspector. You need to edit the curve in the Animation window or the model import settings.
  4. Reference that asset in your script and evaluate it during OnAnimatorIK to determine how much weight to give the IK system during each frame. 0 means the limb will be fully controlled by the animation while 1 means the IK system will be fully in control.
private AnimancerComponent _Animancer;

private ExposedCurve _LeftFootWeight;

private void OnAnimatorIK(int layerIndex)
    var weight = _LeftFootWeight.Evaluate(_Animancer);
    _Animancer.Animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, weight);

The Uneven Ground example demonstrates the use of this feature in more detail.