Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  ObiCloth + character interpolation - how to fix jittering?
#5
(27-09-2023, 07:34 PM)timconkling Wrote: Hey Jose, apologies for necroing this thread after so long! I'm (finally) revisiting the issue.

Yep, totally understand that cloth needs to be updated in `FixedUpdate` (and, because of the way my game works, characters also need to be updated in the `FixedUpdate` timestep as well). I think I did a poor job of explaining the original issue:

My character controller (which is updated in FixedUpdate) performs interpolation in Update, similar to how `ObiUpdater.Interpolate` works. That is, it interpolates between the previous and current states of the characters transform's position and rotation, just before scene rendering. No simulation is happening in this interpolate step; I update my characters (and the rest of the game logic) at 30fps, but render at 60+ fps, and so the interpolation just smoothes out character motion. 

In other words, the game's characters get rendered at a slightly different location than they were last simulated at. What I'd like to do is have the cloth's render location match up with the interpolated character location (WITHOUT performing any additional cloth simulation; the cloth is already simulated, but now it just needs to be shifted slightly to the new interpolated location for rendering purposes - and then shifted back to its proper location before the next cloth simulation step executes).

Does this clarify things at all? Is it possible to achieve what I'm looking for?

Thanks!

Hi Tim,

Sorry for taking so long to reply, your post slipped trough the cracks. Very sorry for that.

Yes, it is possible to do what you need. Particles in Obi have a "renderablePosition" property, which is used to store interpolated positions (when solver interpolation is enabled, which I assume you're already using but found it doesn't work in your case due to the specifics of your custom interpolation system) and used for rendering the cloth. 

The physics simulation outputs particle "positions" in FixedUpdate(), then every frame in LateUpdate() it interpolates the previous and current particle positions and stores the result in "renderablePositions". These values are then used to update the cloth mesh. Renderable positions are not fed back into the next simulation step, they're discarded and re-calculated the next LateUpdate().

So if you're performing custom character interpolation, you can shift the values in solver.renderablePositions so that they match up with your character. This is best done in the solver.OnInterpolate callback event, which is called
after the solver populates the renderablePositions array, but before using it to update the cloth mesh. This will basically overwrite the results of Obi's internal interpolation with your own values right before rendering each frame.

kind regards,
Reply


Messages In This Thread
RE: ObiCloth + character interpolation - how to fix jittering? - by josemendez - 12-10-2023, 06:47 AM