Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  ObiCloth + character interpolation - how to fix jittering?
#2
(06-01-2022, 02:11 AM)timconkling Wrote: In my game, characters are updated in FixedUpdate, and ObiCloth is updated in LateFixedUpdate. Everything works fine:

I'd like to interpolate my characters' transforms in LateUpdate so that their motion is smoother. I'm using a character controller called KinematicCharacterController, which implements interpolation how you'd expect - which is to say, characters have transforms that are restored to their last-ticked position at the start of the character update, and then those transforms are position/rotation-interpolated in LateUpdate.

This causes ugly jittering with my current ObiCloth setup, presumably because characters are not at their simulated positions when they're rendered:

Is there a solution to this? (I'd rather not simulate cloth in LateUpdate if I can avoid it, given the caveats in ObiLateUpdater.)

Hi!

For physics of any kind to be accurate, they must be updated using a fixed timestep ---> must be updated in FixedUpdate().
FixedUpdate happens before Update and LateUpdate every frame. So if you're altering character position in LateUpdate, your character is moving away from the cloth, the cloth does not pickup this change on the same frame (as it's been already updated), and this causes jitter.

However this is not the only jitter source you will encounter. FixedUpdate can be called multiple times per frame, or not called at all some frames. In practice this happens when the rendering frequency is high and your timestep large (eg, 120 fps using a timestep of 0.02) since each frame does not accumulate enough time for the engine to advance one timestep. This will cause jitter because some frames, cloth might not be updated at all but your character controller will.

The only way to get this to work without resorting to update cloth in LateUpdate is to take full control over the update order of both your character controller and the cloth simulation. Things must happen in this specific order:

1) - Character animation
2) - Character interpolation
3) - Cloth simulation.

You will have to modify your character controller so that it performs the interpolation before cloth simulation. This can be done in a variety of ways, the simplest being:

- Hooking onto ObiSolver.OnBeginStep, which is called right before updating the cloth. This is a regular C# event that you can subscribe to.
- Writing your own ObiUpdater component (you can just copy the included ObiFixedUpdater) and insert the character interpolation before cloth sim.

Hope this is of some help. Let me know how it goes!
Reply


Messages In This Thread
RE: ObiCloth + character interpolation - how to fix jittering? - by josemendez - 10-01-2022, 08:36 AM