It is feasible to run the physics simulation on client and server and get the same result?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By DigNZ

I’m working on a game that uses 2D physics - think ‘throwing’ an object. Input is just at the beginning as you throw the object, then the physics play out and you get a result / score.

The game is single player however the scores are recorded and there is a prize element. I need to be able to verify scores ‘independently’ to what the client is reporting.

My thoughts are to capture the touch or mouse input and send that to a headless server that also runs through the game play and verifies that the same result as the client. The reason for this approach is that the server can be ‘queued’ scores can be provisionally added and then verified by the server in due course, there is also an auditable record of how the scores were achieved. For legal reasons there cannot be a chance or random element to this game so this reproducibility also satisfies that requirement.

My question: Is the physics simulation consistent enough that this approach would produce the same results on different machines with the same input? Are there any problems with this approach?

Running some experiments on this seems to show that the same platform (OS) returns the same results to the level that I need, however it is not the same across platforms I assume due to handling floating points numbers.

Example, multiple different 64 bit windows 10 machines are producing the same result on either Windows .exe file or HTML5 export in any browser.

Headless Linux server and HTML5 running on Linux produces the same results but those results are different to the windows builds.

Not compatible enough for the verification method I was looking for. maybe fixed point maths could do this but I think I’m heading down a rabbit hole doing that.

BUT it does seems to be reproducible enough that running the same inputs on the same architecture can be used to verify / replay results. I just need to sychronised that common server platform with the clients.

Unless there is another approach I’ll run the simulation on the server so its always the same and use Zylann’s video for some client side approximation to make things smooth and responsive.

DigNZ | 2019-10-22 00:32

:bust_in_silhouette: Reply From: Zylann

My thoughts are to capture the touch or mouse input and send that to a headless server that also runs through the game play and verifies that the same result as the client.

So your game is networked, you need to solve the same problems as in multiplayer.

My question: Is the physics simulation consistent enough that this approach would produce the same results on different machines with the same input?

No. There is no guarantee for determinism in any of the available physics engines in Godot (Bullet and GodotPhysics). If you are doing this because you don’t want to trust the clients, you may basically have to implement networked physics, where only the simulation happening on the server is taken for valid, the player only seeing an approximation of it.
This video explains this in the context of another game: https://www.youtube.com/watch?v=rtcERbTybj8

In your case, since you are singleplayer, you might not need soo much work on latency and synchronization, maybe just at a lower rate depending on how complex is your simulation.

If your simulation is actually simple enough, you might be able to just not rely on physics at all and implement yours in a deterministic way.

Great video and thanks for the answer. Shame that the physics can’t be ‘replayed’ as it would resolve a number of issues for me.

I’ll see if it makes sense to make a new implementation or else take the networked approach.

Cheers

DigNZ | 2019-10-20 23:43