效果图
设置:
1.
2.
3.对IK的操作的代码要在 void OnAnimatorIK () 这个方法中写
代码:
************************************************
public bool IK=false ;
//目标物体的位置public Transform targetObj;
Animator ani;
void Start () {
ani = GetComponent<Animator>();
}
void OnAnimatorIK () {
if(IK)
{
// 设置 目标旋转对手的权重
ani.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
//设置目标位置对手的权重
ani.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
//设置IK关节跟随目标旋转
ani.SetIKRotation(AvatarIKGoal.RightHand, targetObj.rotation);
//设置IK关节跟随目标位置
ani.SetIKPosition(AvatarIKGoal.RightHand, targetObj.position);
}else
{
//设置目标旋转对手的权重
ani.SetIKRotationWeight(AvatarIKGoal.RightHand, 0);
//设置目标位置对手的权重
ani.SetIKPositionWeight(AvatarIKGoal.RightHand, 0);
}
}