Search Unity

IK weird behaviour

Discussion in 'Animation' started by MikeyJY, Apr 18, 2020.

  1. MikeyJY

    MikeyJY

    Joined:
    Mar 2, 2018
    Posts:
    530
    I have this basic IK code:
    Code (CSharp):
    1. private void OnAnimatorIK()
    2.     {
    3.         animator.SetIKPositionWeight(AvatarIKGoal.RightHand, 1);
    4.         animator.SetIKRotationWeight(AvatarIKGoal.RightHand, 1);
    5.         animator.SetIKPosition(AvatarIKGoal.RightHand, target.position);
    6.         animator.SetIKRotation(AvatarIKGoal.RightHand, target.rotation);
    7.     }
    The target is inside FPSController.
    That causes a problem: When I look in opposite direction of enemy, it is rotating wrong:


    Can you give me the right code of enemy aiming the gun at player or how to solve it?