Unity IK动画

当需要对人物在进行某个动画时可能出现手部或腿部情况不和谐,不符合实际情况如下图时

可发现人物角色的手与所提枪械相距甚远,此时可以使用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);
        }
    }

将添加的两个子物体进行拖入

接下来播放游戏,即可在游戏中控制双手位置进行移动

慢慢进行调整后,对当前位置记录即可。

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值