Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. We're looking for your feedback on the platforms you use and how you use them. Let us know!
    Dismiss Notice
  4. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  6. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  7. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  8. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Hunting the Jerkiness (An issue of Fixed Stepping)

Discussion in 'Physics' started by LightStriker, May 11, 2018.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,303
    We have a complex third person action-RPG where the player is animation-drive (Root Motion).

    Before you ask, we already tried having everything in FixedUpdate or Update.

    Here's the issue; we don't want to force VSync. The player should be allowed to unlock the FPS if he wishes. The game should play great at 30, 40, 60 or even 120 FPS.

    FixedUpdate Issue: If we put the Animator update on FixedUpdate, we get a number of frames not updated. If the Fixed Delta is 0.02 and we run at 60 FPS, we get 1 frame out of 6 without an animation update. The issue becomes more and more drastic as we increase in framerate. For quality, we should run on Update/LateUpdate.

    Update/LateUpdate Issue: While the animation is smoooooth, we get a odd jerkiness in the motion, as the physic stop the Animator motion on frame the physic isn't ticked. If we run at the same Fixed Delta with the same 60 FPS, the animation is updated on all frames, but 1 frame out of 6 the motion is not.

    Clearly we want both the animation AND the motion to be smooth. The higher the framerate, the more pronounce the issue appears. Higher framerate should be smoother, not jerkier!
     
    Last edited: May 11, 2018
  2. ThermodynamicsMakesMeHot

    ThermodynamicsMakesMeHot

    Joined:
    Feb 14, 2015
    Posts:
    188
    Have you tried playing with the timeStep? Certainly sounds like it could help here.
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,303
    Sure... but how can you guaranty you will never skip a frame at higher framerate? Keep changing the timeStep higher or lower to the average of delta time?
     
  4. ThermodynamicsMakesMeHot

    ThermodynamicsMakesMeHot

    Joined:
    Feb 14, 2015
    Posts:
    188
    Well what we did was create a TimeManager that adjusted the timeStep depending on the situation, like you mentioned you can't just leave set at something because it will have issues.

    There is not really an exact science to find the best results, we found the best settings by trial and error. ScriptableObject helps here so you can adjust in realtime and save those changes.
     
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,303
    I'm a bit surprised, because this plagued us for years!

    Moments after posting this thread, I decided to try turning off autoSimulation and to call Physics.Simulate() manually in a manager Update loop.

    Freaking.

    Flawless.

    Even the camera jerkiness in high speed elevators is gone.
     
  6. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,143
    Just calling Physics.Simulate() within Update()? Can you elaborate on this?
     
  7. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,303
    https://docs.unity3d.com/ScriptReference/Physics-autoSimulation.html

    Turning that setting off prevent the physics from advancing the simulation. FixedUpdate is still called, OnTrigger, OnCollision, etc. are still called, but no object are moved around.

    https://docs.unity3d.com/ScriptReference/Physics.Simulate.html

    When Simulate() allows you to step the simulation by the time you supply it. So by running a script on Update, I step the physic simulation every visual frame. That script has a Script Execution Order to make it tick first.

    Possible downside:
    - Not longer possible to be deterministic.
    - OnTrigger/OnCollision/etc are called one frame late.
    - A low framerate may have collision issues, as the physic engine is used to run it's simulation at 50 FPS.
     
  8. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    1,143
    Thanks, that was what I wanted to know. I'm aware of the Physics.autoSimulation setting, but just wondered if it could be used this way for running physics on each visual update.

    Physics hasn't ever been deterministic anyways. Low framerate situations might be worked around by calling Physics.Simulate several times per frame for ensuring some minimum physics update rate.
     
  9. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,303
    Quite true. Just need to be careful as to not make multiple Simulate call ending up dragging the framerate even lower...

    But yeah, it's soooo smoooooth! You wouldn't believe it's not butter!
     
    hippocoder likes this.