Im trying to learn IK animations. On the unity scriptingAPI page I found this example and I tested on the ThirdPersonCharacter from Standard Assets:
using UnityEngine;
using System;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class IK : MonoBehaviour
{
protected Animator animator;
public bool ikActive = false;
public Transform rightHandObj = null;
public Transform lookObj = null;
void Start()
{
animator = GetComponent<Animator>();
}
//a callback for calculating IK
void OnAnimatorIK()
{
if (animator)
{
//if the IK is active, set the position and rotation directly to the goal.
if (ikActive)
{
// Set the look __target position__, if one has been assigned
if (lookObj != null)
{
animator.SetLookAtWeight(1);
animator.SetLookAtPosition(lookObj.position);
}
// Set the right hand target position and rotation, if one has been assigned
if (rightHandObj != null)
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
animator.SetIKPosition(AvatarIKGoal.RightHand, rightHandObj.position);
animator.SetIKRotation(AvatarIKGoal.RightHand, rightHandObj.rotation);
}
}
//if the IK is not active, set the position and rotation of the hand and head back to the original position
else
{
animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 0);
animator.SetLookAtWeight(0);
}
}
}
}
I set the rightHandObj a moving cylinder. I noticed that the character is moving the right arm but the palm is frozen:
The AvatarIKGoal has only 4 proprieties: Right/Left Hand/Foot. I guess I need an humanoid Avatar Mask to control more body parts(like thumbs, shoulders, head, etc.)! I found this enumeration: AvatarMaskBodyPart that has more humanoid bones! The problem is that SetIKPositionWeight doesn’t accept it as a parameter and I don’t know how to use this!
EDIT: Sorry if I don’t reply to your answer because I will be AFK some hours!
