By Basea Basilia

2019-03-14 18:57:46 8 Comments

I'm using C# Box2D library for my server and client, they have similar world.step(), iterations and update function. At the same time they have different physics' results, difference is not fixed, it may be 1-2% or more than 10%. My timestep is 0.02f and 10 iterations(for both). Code of the client and the server is almost the same. I believe it's because of I have the same timestep on both, server and client, but their code execution speed may be quite different. How can I get the same results in different applications/on different computers?


@Lunin 2019-03-15 06:59:38

Getting two physics systems to do exactly the same thing is a very difficult problem that requires having the physics simulations be entirely deterministic. Even incredibly tiny differences between the two will accumulate into wildly different outcomes given time. Searching about Box2D determinism it seems that you can't count on that in this case due to differences in how different processors handle their floating point math.

That being said, you say that the simulations are still relatively close, so what you can do is allow the client to run its simulation, but periodically have the server send state to the client for it to update its model. Doing things this way does mean that the client's version of things will differ in small ways a fair amount of the time so you can't rely on anything the client system says happened until the server verifies... but really for a networked game that is already the case.

The key is going to be to find a happy balance between fluidity (client simulated) and correctness (server simulated) so the game feels as good as possible on all sides while still having all the meaningful gameplay elements in the right places. If you've got purely decorative elements like physics based particle explosions that don't move gameplay elements, feel free to not even bother syncing those and let the simulations fly!

Related Questions

Sponsored Content

0 Answered Questions

1 Answered Questions

[SOLVED] Box2d Fixed Timestep and Interpolation

2 Answered Questions

[SOLVED] Box2D - World step on Android game using LibGDX

0 Answered Questions

Unity 5 Distributed Physics in Client Server Model

2 Answered Questions

[SOLVED] Client-side physics simulation

4 Answered Questions

[SOLVED] Run a physics simulation on both client and server?

  • 2013-02-06 04:59:38
  • Venesectrix
  • 2911 View
  • 13 Score
  • 4 Answer
  • Tags:   physics networking

2 Answered Questions

[SOLVED] Determinism in multiplayer simulation with Box2D, and single computer

  • 2012-05-13 17:14:28
  • Jake
  • 1827 View
  • 4 Score
  • 2 Answer
  • Tags:   box2d multiplayer

2 Answered Questions

[SOLVED] Client/Server Object updates seems to run at different speeds

  • 2012-08-08 19:37:57
  • EursPravus
  • 297 View
  • 1 Score
  • 2 Answer
  • Tags:   xna c# networking

Sponsored Content