当需要对人物在进行某个动画时可能出现手部或腿部情况不和谐,不符合实际情况如下图时
可发现人物角色的手与所提枪械相距甚远,此时可以使用IK动画进行调整,首先在Animator找到当前动画层,勾选IK
找到当前物体在人物模型的位置,对物体添加子物体,分别为RightHand,LeftHand
在对控制敌人动画的脚本中添加下列代码
public Transform LeftHandPoint;
public Transform RightHandPoint;
private void OnAnimatorIK(int layerIndex)
{
if(layerIndex==0)
{
//左手IK
anim.SetIKPosition (AvatarIKGoal.LeftHand, LeftHandPoint.position);
anim.SetIKPositionWeight(AvatarIKGoal.LeftHand, 1f);
anim.SetIKRotation(AvatarIKGoal.LeftHand, LeftHandPoint.rotation);
anim.SetIKRotationWeight(AvatarIKGoal.LeftHand, 1f);
//右手IK
anim.SetIKPosition(AvatarIKGoal.RightHand, RightHandPoint.position);
anim.SetIKPositionWeight(AvatarIKGoal.RightHand, 1f);
anim.SetIKRotation(AvatarIKGoal.RightHand, RightHandPoint.rotation);
anim.SetIKRotationWeight(AvatarIKGoal.RightHand, 1f);
}
}
将添加的两个子物体进行拖入
接下来播放游戏,即可在游戏中控制双手位置进行移动
慢慢进行调整后,对当前位置记录即可。