Hi animation experts,
I’ve read the explanation about deterministic lockstep here
Sometimes it is important to make sure animations, physics and game logic code are in sync and decoupled by frame-rate variance. This might be useful to be able to replay how a scene evolved, given the same initial condition and inputs, or to minimize differences on multiple clients in a multi-user environment
But I fail to understand concretely how I can use it to sync multiple clients.
What I understand is:
- The engine in each client needs to be started with the deterministic lockstep option turned on, which is easy enough.
- There are onBeforeStepObservable and onAfterStepObservable callbacks that are available to do whatever game logic we want.
- In the documentation playground the callback can console.log theScene.getStepId()
- Subsequent runs of the playground will console.log a bouncing sphere stopping at the same stepId every time.
Suppose I have multiple clients and I want them to see the same (or close enough) physics animations as they each knock over boxes and shoot bouncing balls etc.
- Since each client may have started their own engine a little sooner or a little later, is it important to set each client to the same stepId all at the same time in order to have each client experience the same animations at the same time?
- If so, is there a way to set all client’s engines to the same initial stepId? I couldn’t find a single PG example that uses setStepId.
- As client A knocks over a box at StepId X (for client A), assuming we can send this web-socket message over to client B, how can we convey to client B that the physics impulse of knocking over the box should have happened back at StepId X, when by the time client B receives the message we’re already slightly past that point in time? Is there a way client B can “catch-up” to the proper animation of the box knocking over? Like saying “this happened 10 frames ago, but don’t bother rendering them, just render where you think the box is now”. Or like saying to your bank account, “these are transactions you didn’t know about, now update your balance”.
- Can you ‘rewind’ the engine to an earlier point in time at stepID X, add an impulse that happened, then ‘fast forward’ the engine to the current point in time X + 20 frames and continue rendering the aftermath?
In summary, my intuition is telling me:
- Each client is running their own independent physics simulation that happens to be starting around the same time.
- Client’s actions can be logged and shared as an array of facts, of physics impulses and forces etc that occurred at stepID.
- … that’s sort of where my intuition ends. In what ways can we sync (add facts, that may have already happened) to each client’s engine and expect them to adjust dynamically and smoothly? And does deterministic lock-step help us accomplish this?
Any hints would be appreciated! Thanks!