# 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
}

{
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.

• Can I ask how to put up this animated image for your question? Thx Nov 27, 2015 at 13:01

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.

• See my answer for why generally speaking, LateUpdate is more suited for this usage than Update. Aug 14, 2014 at 3:28

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.

Generally speaking any kind of "Look" maneuver that's not physics related, including head movements and cameras will use LateUpdate (and in fact, I recall the default camera scripts use it as well).

• Note that if the scripts that look at things are set to execute after all others, this is not necessary. Good point though.
– user15805
Aug 14, 2014 at 7:43
• I don't understand what you mean. If you're referring to script order execution for the Update method, it won't affect whether Update is called before LateUpdate, it's only relative to other Update methods. And it's still not a good idea to rely on script order execution more than is needed, LateUpdate was specially made to handle this case, the docs say as much. Aug 14, 2014 at 7:49
• Yes, it won't affect Update being called before LateUpdate. But it won't allow scripts that update objects that are being looked at to update before the objects looking at them update. I did not say it is a good idea to rely on script execution order more than is needed, I merely mentioned the possibility.
– user15805
Aug 14, 2014 at 7:51
• There's more to it than that though. Yields in co-routines won't ever have happened before Update is called no matter what execution order is in use and most importantly internal animation updates won't have either. LateUpdate is what should be used for this purpose. Update may appear to work, but will eventually lead to hard to track down bugs. Aug 14, 2014 at 7:55
• I'm sure we can branch out to even more such particular cases if we try :) I'll keep the yield thing in mind though.
– user15805
Aug 14, 2014 at 7:56

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

• OnAnimatorIK() is called just before LateUpdate(), and both are called after update and before the scene rendering, thats why both are suitable for calling SetLookAtPosition() (execution order). But maybe you are right, perhaps this function is meant to be call from OnAnimatorIK(). Nov 18, 2014 at 15:53