All Classes Namespaces Functions Variables Enumerations Properties Pages
Inverse Kinematics

PuppetMaster can be used together with Unity's own built-in Animator IK as well as Final IK. The former is limited to Humanoids only and can be used to alter the target pose programmatically before the PuppetMaster reads it for following. Final IK opens up much more possibilities such as modifying the pose with full body IK or applying an IK pass on top of the physical simulation for cosmetic corrections or accurate aiming.

Final IK:

To use PuppetMaster with Final IK, import both packages to the project, then import also "Plugins/RootMotion/PuppetMaster/_Integration/Final-IK.unitypackage". The package comes with scenes and scripts demonstrating the application of IK both before and after PuppetMaster solves.

IK Before Physics:

We might be interested in using IK to change the Target pose for various reasons, for example keeping balance, aiming, grabbing, protecting from incoming collisions or even procedural locomotion. When using Unity's built-in IK solution, it will be automatically applied on top of the animation in the Mecanim update cycle. The components of Final IK will also update by default before PuppetMaster reads. If you need them to be updated in a specific order, you can use the IKBeforePhysics.cs component or disable them and update their solvers manually using the PuppetMaster.OnRead delegate:

public PuppetMaster puppetMaster;
public IK[] IKComponents;
void Start() {
// Register to get a call from PuppetMaster
puppetMaster.OnRead += OnRead;
// Take control of updating IK solvers
foreach (IK ik in IKComponents) ik.enabled = false;
}
void OnRead() {
if (!enabled) return;
// Solve IK before PuppetMaster reads the pose of the character
foreach (IK ik in IKComponents) ik.GetIKSolver().Update();
}
// Cleaning up the delegates
void OnDestroy() {
if (puppetMaster != null) {
puppetMaster.OnRead -= OnRead;
}
}

IK After Physics:

Each frame PuppetMaster is done solving and mapping the Target character to the ragdoll, we have a chance to make minor adjustments (that don't change the physics anymore) to the character pose. This can be useful for example when making sure hands are perfectly fixed to some points or doing aiming correction with AimIK. Unity's built-in IK can not be applied after PuppetMaster has mapped the Target character to the ragdoll pose. Final IK components can be updated whenever necessary and in this case we need to do it in the PuppetMaster.OnWrite delegate:

public PuppetMaster puppetMaster;
public IK[] IKComponents;
void Start() {
// Register to get some calls from PuppetMaster
puppetMaster.OnWrite += OnWrite;
// Take control of updating IK solvers
foreach (IK ik in IKComponents) ik.enabled = false;
}
// PuppetMaster calls this when it is done mapping the animated character to the ragdoll so if we can apply our kinematic adjustments to it now
void OnWrite() {
if (!enabled) return;
// Solve IK after PuppetMaster writes the solved pose on the animated character.
foreach (IK ik in IKComponents) ik.GetIKSolver().Update();
}
// Cleaning up the delegates
void OnDestroy() {
if (puppetMaster != null) {
puppetMaster.OnWrite -= OnWrite;
}
}