Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question How to limit the rotation foot with IK?

Discussion in 'Animation' started by Zimaell, Jun 21, 2023.

  1. Zimaell

    Zimaell

    Joined:
    May 7, 2020
    Posts:
    425
    when setting the leg according to the normal, the leg does not always look realistic, sometimes it bends very strongly.
    How to set a limit at which the leg will not be able to turn further?

    Code (CSharp):
    1. private void SetFootRot(){
    2.      LFRotationIK = animator.GetIKRotation(AvatarIKGoal.LeftFoot);
    3.      LFRotationIKTemp = Quaternion.Lerp(LFRotationIKTemp, GetFootRotate(LFNormal) * LFRotationIK, Time.fixedDeltaTime * 15f);
    4.      LFRotationIK = LFRotationIKTemp;
    5.      animator.SetIKRotation(AvatarIKGoal.LeftFoot, LFRotationIK);
    6.      // also Right Foot
    7.      }
    8. private Quaternion GetFootRotate(Vector3 normal){
    9.      Vector3 rotAxis = Vector3.Cross(Vector3.up, normal);
    10.      float angle = Vector3.Angle(Vector3.up, normal);
    11.      return Quaternion.AngleAxis(angle, rotAxis);
    12.      }
     
    Last edited: Jun 21, 2023