Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

Body Jittering

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
    HeadOrientation();
}   

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.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
See my answer for why generally speaking, LateUpdate is more suited for this usage than Update. –  Assorted Trailmix Aug 14 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).

share|improve this answer
    
Note that if the scripts that look at things are set to execute after all others, this is not necessary. Good point though. –  Alex M. Aug 14 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. –  Assorted Trailmix Aug 14 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. –  Alex M. Aug 14 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. –  Assorted Trailmix Aug 14 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. –  Alex M. Aug 14 at 7:56

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

share|improve this answer
    
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(). –  Celtc Nov 18 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.