Unity – SetLookAtPosition() – Body Jittering?

Unity – SetLookAtPosition() – Body Jittering?

I'm working on a third person controller and I'm trying to make character look at the same point as the camera. The problem is that the character jitters all the time the SetLookAtPosition() starts working. Here is a pic:

Everything works great if don't call the LookAt function. Even commenting all the other code on FixedUpdate() and Update() functions the problem remains. The code goes like this:
void FixedUpdate()
    // Commented Code

    // Movimiento de Cabeza

private void HeadOrientation()
    animator.SetLookAtPosition(animator.GetBoneTransform(HumanBodyBones.Head).position + gameCamera.transform.forward);
    animator.SetLookAtWeight(1f, .4f, 1f, 1f, .8f);

Hope someone knows what's happening. Thanks and sory for my bad english!

After trying differents things, it seems that the SetLookAtPosition() function needs to be call in the Update() function, not in the FixedUpdate().
I would appreciate if someone could explain why it needs to be like this.


Answer 1:

Apply any transformations inside the Update() method, rather than FixedUpdate(). Fixed update runs independently of your framerate, and this will inevitably cause stutter. Think that there may be a number of frames displayed without any call to FixedUpdate() in-between (the update is performed “late”).

Aside from dealing with rigidbodies, you should have no use for FixedUpdate() in most typical projects.

Answer 2:

The other answers are on the correct path, but note that LateUpdate is specifically useful for cases like this.

Using Update can cause “race conditions” of sorts, where the object you’re tracking is updated before your object looks at it, causing a jitter at higher speeds.

The difference between the two is:

LateUpdate methods are called after all Update methods have been called.

Answer 3:

I had this same problem. I found out you have to call this from OnAnimatorIK, not an update function.