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!
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?
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.
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.
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.
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.