Physics interpolation/extrapolation - does it work?

I’ve had my fixed timestep set to 1/60th of a second, and everything is fairly smooth.

But I’ve been experimenting with a larger timestep (1/30th or higher), wondering if I can use this to improve performance mobile. I’ve also been messing with slow-motion effects (changing Time.timeScale) - and in these cases, there is judder related to the fixed tiemstep.

Without interpolation, things are juddery, but the physics behaves well enough. Interpolation/Extrapolation is supposed to be the solution, but I’ve not managed to get decent results out of either, so far.

I’ve tried both modes, and turned on interpolation (then later, extrapolation) for all rigidbodies in an object, but it doesn’t seem to be working well at all:

  • Ragdolls become flickery/jumpy, limbs glitch in unpleasant ways.
  • Mecanim-driven characters don’t appear to interpolate at all, and appear to judder along at the fixed timestep

Is this normal? Are these solvable problems? (have I just missed something obvious?) Or is the only solution to keep the fixed timestep small?

(It shouldn’t to me applying forces/moving objects in Update(), as ragdolls are purely under physics control, and characters are mostly under Mecanim control - although I do add some code-driven rotation to help with turning)

Providing physics are all calculated inside FixedUpdate and you’re not setting transforms directly, then physics should be incredibly smooth with interpolation (not extrapolation). Suspect extra is probably for networked physics or something.

They will probably glitch if you move them around in Update.

That’s what I’d expect… but it doesn’t match the behavior that I’m currently seeing with ragdolls/mecanim characters.

Can one-off movements/forces applied in Update() ‘break’ the interpolation afterwards, when the object is moving entirely under physics control after initially setting the position? - I’ll have to do some more testing in a simpler scene

Yes it can. Do all the movements (AddForce, etc…) in fixedUpdate.

From docs: http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.FixedUpdate.html

I’ve been experimenting again in a test scene. Some interesting results:

  • Objects placed in the scene and never disabled interpolate fine. Nice and smooth, as expected. Tested with a ragdoll.

  • Simply turning them on and off via SetActive() breaks their interpolation completely - they become a juddery mess (it’s clearly the interpolation glitching back and forth - between current/previous positions - not the physics itself, which works fine with interpolation off)

(However, the object is being turned on/off via an NGUI button, which I believe is being updated in an Update, not a FixedUpdate. But surely this should be safe - simply activating/deactivating objects shouldn’t need to be deferred to the next FixedUpdate?)

Does everybody just use small fixed timesteps and no interpolation? - it’s looking like interpolation is either a bit broken or incredibly fragile???

We have good results right down to 5fps update in fixedupdate. It’s probably your code not resetting velocity and angularVelocity to zero.

Hmm, I’m struggling to find the cause - the ‘problem ragdolls’ are broken the first time they get enabled, so it shouldn’t be existing forces, and I don’t think I’ve got any scripts left applying forces - just one to switch from animated to ragdoll in this test scene. But once it gets into the ‘broken state’, it stays broken, as if something is messing up the internal interpolation state and it never recovers.

I’ve been trying to reproduce the problem in a very minimal test scene (cubes with a couple of physics joints, rather than a complete ragdoll), but so far it’s behaving itself…

Having the same issue. Can repro 100% in a very simple setting. Create a character with a ragdoll with interpolation and a 1/10 timescale. Start him disabled. Run Unity, enable him via inspector. Works fine. Still in the same run, disable and re-enable him again via the inspector. Ragdoll and physics become jittery.

It seems that the first time you deactivate an active ragdoll, it will be forever broken.

Given there’s no such thing as a real ragdoll in Unity, it’s hard to diagnose your problems.

Well, I’m using the Game Object → 3D Objects → Ragdoll… entry to create one. Nonetheless, I found what the issue is. If you change the interpolation method on the rigid body before the Awake() is called (like from a spawning pool manager), you corrupt your rigid bodies.

Make sure you change the interpolation in an Awake() or similar function, when the actual rigid bodies are already active. It now works smoothly for me (although the activate/deactivate bug is still a real issue; logged it to Unity team.)

Game Object → 3D Objects → Ragdoll is unfortunately a bit of a rubbish part of unity that’s just a wizard or helper to use the physics engine. It’s not really a ragdoll and often gets things horribly wrong, buggy thing it is.

Glad you found the problem.

That ragdoll wizard is a good starting point, but, granted, it often has some… interesting… results. Hope it helps, bluescrn.

I’m still having the issue with the activate/deactivate :frowning: