Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

IK back movement not working?

Discussion in 'Scripting' started by skyLark9, Jan 19, 2019.

  1. skyLark9

    skyLark9

    Joined:
    May 2, 2018
    Posts:
    135
    I have issue in my script that when my doll look at target using IK he looks smoothly at it. But when I turn off target bool I need my doll to get back to normal position or idle animation smoothly. What I got is transfer from one position to another in less than one second !
    Code (CSharp):
    1.     public Animator animator;
    2.     public bool Activate_doll = false; // control it from inspector
    3.     public Transform lookObj; // doll target
    4.     public float weight, bodyWeight;
    5.  
    6.     void Update()
    7.     {
    8.  
    9.         if (Activate_doll )
    10.         {
    11.             weight = Mathf.Lerp(weight, 1f, Time.deltaTime * 1);
    12.             bodyWeight = Mathf.Lerp(bodyWeight, 0.5f, Time.deltaTime * 1);
    13.  
    14.         }
    15.        
    16.         else
    17.         {
    18.             weight = Mathf.Lerp(weight, 0f, Time.deltaTime * 1);
    19.             bodyWeight = Mathf.Lerp(bodyWeight, 0f, Time.deltaTime * 1);
    20.  
    21.         }
    22.  
    23.     } // end Uploade
    24.  
    25.     void OnAnimatorIK()
    26.     {
    27.        
    28.             if (Activate_doll )
    29.             {
    30.                     animator.SetLookAtWeight(weight, bodyWeight);
    31.                     animator.SetLookAtPosition(lookObj.position);
    32.             }
    33.  
    34.             else
    35.             {
    36.                 animator.SetLookAtWeight(weight, bodyWeight);  // he never get back smoothly to normal position !!!    
    37.             }
    38.        
    39.     }