Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Resetting head IK to original position

Discussion in 'Editor & General Support' started by sonderistic, Sep 11, 2019.

  1. sonderistic

    sonderistic

    Joined:
    Jan 4, 2017
    Posts:
    6
    Hi, I'm currently using Unity's IK system. For some reason whenever I try to reset the "SetLookAtPosition" function by lerping the look-at weight to 0, the model's head always starts from looking to the right back to the middle, and not from the current head rotation. I've tried it with several models and they all seem to be suffering from this same problem, so I think it's safe to assume that it isn't the rig. Any help would be greatly appreciated.

    My code currently:
    if (Vector3.Angle(transform.forward, playerPos.position - transform.position) < lookAtAngleThreshold)
    {
    anim.SetLookAtPosition(playerPos.position + Vector3.up);
    currentLookAtWeight = Mathf.Lerp(currentLookAtWeight, lookAtWeight, Time.deltaTime);
    anim.SetLookAtWeight(currentLookAtWeight);
    }
    else
    {
    currentLookAtWeight = Mathf.Lerp(currentLookAtWeight, 0f, Time.deltaTime);
    anim.SetLookAtWeight(currentLookAtWeight);
    }
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    5,862
    How are you doing your runtime debugging? Debug.Log is your friend. Granted it doesn't solve your issue, but would give you insight into that might be going on.
     
  3. sonderistic

    sonderistic

    Joined:
    Jan 4, 2017
    Posts:
    6
    The main problem here is that lerping currentLookAtWeight back to 0 causes the head to snap facing right before lerping to it's original (looking forward) position. I've debugged the "currentLookAtWeight" and its value is changing correctly.

    Is there a better way to reset SetLookAtPosition?