Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Jittering Character Movement

Discussion in 'Scripting' started by 0tacun, Nov 24, 2014.

  1. 0tacun

    0tacun

    Joined:
    Jun 23, 2013
    Posts:
    245
    For a pretty long time I have the problem that my character is always jittering while moving. I noticed this occures when the framerate is not in sync with the fixed update loop.

    Here is an example: https://dl.dropboxusercontent.com/u/78559347/Webplayer.html

    Move with w,a,s,d and switch the targetFramerate with the keys z and u.

    Even with synced frequencies you will notice a small hiccup from time to time.

    I'm using root motion with an interpolated rigidbody. This also means I'm not moving the character with code, only setting the parameters for mecanim. The camera script is in the LateUpdate() loop. Changing it to Update() or FixedUpdate didn't fixed anything.

    Any advices to achive fluidty?
     
  2. PolymorphiK Games

    PolymorphiK Games

    Joined:
    Oct 5, 2014
    Posts:
    51
    The dropbox link is a dead link, can you try to repost it so I can test it?
     
  3. 0tacun

    0tacun

    Joined:
    Jun 23, 2013
    Posts:
    245
    Done, I hope it worked.
     
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
  5. PolymorphiK Games

    PolymorphiK Games

    Joined:
    Oct 5, 2014
    Posts:
    51
    Hmm...how do you have the camera following the player? What is in Fixed update and Update?
     
  6. 0tacun

    0tacun

    Joined:
    Jun 23, 2013
    Posts:
    245
    Thank you both for your replys.

    @PolymorphiK Games: It is in LateUpdate, however changing it to fixed/normal update doens't help, when the frequency of the visual timestep is different to the physics timestep. This means with an fixed timestep of 0.02 I have to fix my framerate to 50fps. And this would kill the purpose of the existence of two different update loops.

    @Stardog: Yes the character is only jittering while moving. Thank you for the information. I noticed that using Vector3.MoveTowards is more stable than using Vector3.Lerp. In your suggested threads someone mentioned using some additonal constants with Time.deltaTime. However this resulted that the camera was virtually attached to the targetpoint with no camera smoothing affect. Also to fix myself the somehow broken timestep looks pretty cumbersome.

    I guess I will stick to MoveTowards with not smoothing effect.
     
  7. DylanYasen

    DylanYasen

    Joined:
    Oct 9, 2013
    Posts:
    50
    I believe this is an animation transition problem.
    you might have set animation to run some where in an update loop
     
  8. LudiKha

    LudiKha

    Joined:
    Feb 15, 2014
    Posts:
    140
    It's not a transition problem, since the animation plays in full. Otherwise it'd keep repeating the first part of the run animation ad infinitum. Also, the character jitters when you fall off the ledge (when not playing any looping animation). This indicates that it is a positioning problem. Can you post some more information regarding how you do the positioning?
     
  9. 0tacun

    0tacun

    Joined:
    Jun 23, 2013
    Posts:
    245
    The character positioning works with root motion and interpolated rigid body, for the camera I'm setting the position with vector3.lerp().

    It looks like the camera or character is lagging one frame behind and jumps on the next frame. As already stated when the timesteps are equal the problem nearly vanishes. But it still has some jumps sometimes.

    Interesting links:

    http://answers.unity3d.com/questions/275016/updatefixedupdate-motion-stutter-not-another-novic.html

    http://answers.unity3d.com/questions/820924/physics-first-person-camera-jitter.html
     
  10. Manny Calavera

    Manny Calavera

    Joined:
    Oct 19, 2011
    Posts:
    205
  11. 0tacun

    0tacun

    Joined:
    Jun 23, 2013
    Posts:
    245
    Ok I think it is fixed somehow. Thanks a lot for all your help!

    What I did:
    -dropped Application.targetFramerate
    -camera movement in Update()
    -camera changing position uses currently Vector3.MoveTowards
    -Vsync set to one blank

    It works now in my test scene, but I check later how it behaves under game conditions.