OnAnimatorIK(int)
Callback for setting up animation IK (inverse kinematics).
Read time 1 minuteLast updated 3 days ago
Definition
- Type: Method
- Namespace: UnityEngine
OnAnimatorIK()
public void OnAnimatorIK(int layerIndex)
Parameters
The index of the layer on which the IK solver is called.
Remarks
OnAnimatorIKOnAnimatorIK- The Animator component must reference an Avatar configured as Humanoid. Generic or Legacy avatars do not support IK.
- The Animator Controller layer you want to process IK on must have the IK Pass option enabled.
- The Animator component must be enabled and playing an animation on the GameObject.
- The script containing must be attached to the GameObject with the Animator component.
OnAnimatorIK
Common uses include:
- Setting the position and rotation of IK goals, such as hands and feet, to interact with objects or reach targets in the environment.
- Blending between animation-driven and IK-driven motion by adjusting IK weights.
- Creating procedural animations, such as looking at a target or reaching for an object.
Examples
using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{ float leftFootPositionWeight; float leftFootRotationWeight; Transform leftFootObj; private Animator animator; void Start() { animator = GetComponent<Animator>(); } void OnAnimatorIK(int layerIndex) { animator.SetIKPositionWeight(AvatarIKGoal.LeftFoot, leftFootPositionWeight); animator.SetIKRotationWeight(AvatarIKGoal.LeftFoot, leftFootRotationWeight); animator.SetIKPosition(AvatarIKGoal.LeftFoot, leftFootObj.position); animator.SetIKRotation(AvatarIKGoal.LeftFoot, leftFootObj.rotation); }}