Replicate Inputs / physics

Hi, i’m fairly new to Physics engines and how do they do their tasks, but i’m pretty sure my idea is doable.

Besides the fact that when experimenting with deterministic physics simulation i think i found a bug, where a rigidBody with collision Mask = 0 collides with a static one with mask = 0 behaves differently than if the first had mask = 1.

So yeah, this is about replicating physics.
I have a fixedUpdate function inside the normal update one, if time elapsed > fixedTimestep it adds 1 to physics frames and also calculates how many frames it went past.

So if it took 40ms last update it went past 2 times (15ms fixedTimeStep).

I also have an array of booleans, containing the input for each frame to be processed, every physics frame it takes the input from inputs[physicsFrame] and apply a force to rigidBody if it’s true (force is always the same cause it’s a fixedUpdate).

Then i have two capsules with different mask, so they can overlap to show the result of simulation.

The second capsule inputs array starts with more 0s to delay the first capsule inputs from the other.

THE PROBLEM:
Let’s say the second capsule needs to process 10th frame’s input, and the update loop takes 40ms, it would need to also process 11th. If i apply them both in one update loop, they get desynced.
Otherwise if the update never exceeds 1 physics frame per update, it works perfectly, both capsules end at same position.

Is there any Solutions available at the moment?
I think there’s the need of a simulatePhysics() function.
I hope i explained everything well enough.

Hi @Lxrlvsh_Lvsh and welcome,

So, I am not sure if there is any other solution other than what you’re proposing: having a method to simulate physics, in a single instant, several steps forward (and why not backwards, may be useful as well).

You can submit a feature request about it in the engine repo, though it may be a while, if not at all, tackled since its use case isn’t that common.

In the meantime you can study how the engine boots Ammo.js in the following class:

And you can do something similar on your own, have a second Ammo.js instance that you can feed input and control how often and how many steps it simulates.

It can take some effort to put in place, but there are people that have done so in the past (decouple physics).