Physics Time Scale for Multi-Player game...

Quick question…

I have a game that involves throwing a ball (similar to bowling).

I have the physics for the game working correctly.  I am now trying to convert this game into a multiplayer game.

This might be a dumb question…but to keep the physics simulation identical over the network, is it possible when a player takes “a shot” that the Physics Timescale is increased dramatically, positions of the balls are recorded and then simply “replayed” to both client devices after the simulation is completed at normal speed?

So, in summary:

  1. Player A “throws ball”

  2. Device runs simulation at very fast time scale behind the scenes (recording each ball position at each time step)

  3. Player A & B are then simply given a realplay at normal (slower) speed to ensure both devices see the identical simulation.

Is this a bad idea for a multi-player game?

Hi Byron,

I’m not quite clear on the purpose of “recording each ball position”. What would be the reason for that? To show like a preview of the shot? To “record” it for replay or something?

Brent

I would like to record it and replay back on both devices so ensure that the physics simulations (the balls interacting with each other) are identical on both devices.

My understanding is that box2d physics is non-deterministic and therefore I cannot expect the exact same results would happen on both devices.  My idea is to simply run the simulation of the balls hitting each other at super high speed, record the movement, and then “replay” it on each device at a normal speed.  This will ensure that both devices see identical versions of the physics objects interacting with each other in a multiplayer environment.  

This is only a theoretical approach right now to see if it is even possible.

Does that make sense?  Otherwise, how do you consistently run a physics simulation across multiple devices with a non-deterministic physics engine… just running the idea by the community to see if it is a bad or good idea.

Actually that seems like a completely valid idea. :slight_smile:

I guess you just need to determine how fast you want to speed up the physics scale and how many “captures” you want to collect for a smooth replay.

Brent

That is exactly my dilemma.  

I guess my question is: Can a Physics Time Scale be increased dramatically and still capture position data at a reasonable rate that the animation will look good at normal scale.  This might solve my multi-player issues for non-deterministic physics.

Thanks in advance…

leaving aside the multiplayer aspect, i doubt you could get even ONE device to do what you describe.  that is, the results of the following two simulations would differ even if you’re able to recreate exactly the same starting conditions::  

  1. take 1000 steps (for example) with step time of 0.01s (for example) = 10s elapsed

  2. take 100 steps (for example) with step time of 0.1s (for example) = 10s elapsed

same time elapsed, right?  same results?  no, the integration quality would differ considerably.  you’d expect scenario 2 to seem “coarser”/“more approximate” than scenario 1.    upping the iterations in scenario 2 won’t create an exact match either.  and this difference in integration step will be far more significant than the “non-deterministic” aspects of box2d.

should be easy enough to test - craft a small testbench world to mimic your game, run it once from scratch with each of the two fixed time steps, calling pause() after appropriate number of frames to equal same real time elapsed, then compare results.  if that’s a “fail” on just one device, then abandon for multiplayer.

fwiw, hth

Exactly the type of feedback I was looking for… thank you!

Great suggestions…

B

My suggestion is you let the first player simply do the run-through in real-time and grab from there before passing the info over to the other player. It really depends on how ‘instant’ you want it to be, but I feel like someone playing remotely isn’t likely to notice a delay of anything even up to maybe 10 seconds (as long as he/she is aware the other player is active and hasn’t simply fallen asleep - keep players aware of activity and they have a bit more patience).

Hi @byron5,

Since the time this was originally posted, we added an API to control the speed scale of the physics engine:

https://docs.coronalabs.com/api/library/physics/setTimeScale.html

Brent

Hi Byron,

I’m not quite clear on the purpose of “recording each ball position”. What would be the reason for that? To show like a preview of the shot? To “record” it for replay or something?

Brent

I would like to record it and replay back on both devices so ensure that the physics simulations (the balls interacting with each other) are identical on both devices.

My understanding is that box2d physics is non-deterministic and therefore I cannot expect the exact same results would happen on both devices.  My idea is to simply run the simulation of the balls hitting each other at super high speed, record the movement, and then “replay” it on each device at a normal speed.  This will ensure that both devices see identical versions of the physics objects interacting with each other in a multiplayer environment.  

This is only a theoretical approach right now to see if it is even possible.

Does that make sense?  Otherwise, how do you consistently run a physics simulation across multiple devices with a non-deterministic physics engine… just running the idea by the community to see if it is a bad or good idea.

Actually that seems like a completely valid idea. :slight_smile:

I guess you just need to determine how fast you want to speed up the physics scale and how many “captures” you want to collect for a smooth replay.

Brent

That is exactly my dilemma.  

I guess my question is: Can a Physics Time Scale be increased dramatically and still capture position data at a reasonable rate that the animation will look good at normal scale.  This might solve my multi-player issues for non-deterministic physics.

Thanks in advance…

leaving aside the multiplayer aspect, i doubt you could get even ONE device to do what you describe.  that is, the results of the following two simulations would differ even if you’re able to recreate exactly the same starting conditions::  

  1. take 1000 steps (for example) with step time of 0.01s (for example) = 10s elapsed

  2. take 100 steps (for example) with step time of 0.1s (for example) = 10s elapsed

same time elapsed, right?  same results?  no, the integration quality would differ considerably.  you’d expect scenario 2 to seem “coarser”/“more approximate” than scenario 1.    upping the iterations in scenario 2 won’t create an exact match either.  and this difference in integration step will be far more significant than the “non-deterministic” aspects of box2d.

should be easy enough to test - craft a small testbench world to mimic your game, run it once from scratch with each of the two fixed time steps, calling pause() after appropriate number of frames to equal same real time elapsed, then compare results.  if that’s a “fail” on just one device, then abandon for multiplayer.

fwiw, hth

Exactly the type of feedback I was looking for… thank you!

Great suggestions…

B

My suggestion is you let the first player simply do the run-through in real-time and grab from there before passing the info over to the other player. It really depends on how ‘instant’ you want it to be, but I feel like someone playing remotely isn’t likely to notice a delay of anything even up to maybe 10 seconds (as long as he/she is aware the other player is active and hasn’t simply fallen asleep - keep players aware of activity and they have a bit more patience).

Hi @byron5,

Since the time this was originally posted, we added an API to control the speed scale of the physics engine:

https://docs.coronalabs.com/api/library/physics/setTimeScale.html

Brent