Deterministic Lock-step in Unity3D(iOS/Android)
Posted: Thu Mar 12, 2015 1:50 am
Hello Norbo,
First off, I would just like to thank you for making this amazing engine.
I have played around with it for few months now and basing my upcoming multiplayer app on it.
I am currently developing a game for Android and mobile iOS devices. I am using Unity3D and BEPUphysics .Net 3.5 v1.30.
Initial I used the physics engine to run on my server and had great results syncing players by just sending the transform of the objects. However, the main problem with this model is latency, bandwidth and having to run the physics on my server for each game. Since from playing around with BEPUphysics, I learned it is pretty good at being deterministic, so I decided to program a lock-step version of my network. It turns out that it works out really well and very responsive.
After some initial testing of syncing my PC and Nexus 5 Android, everything seemed to sync really well between my PC and android. Even in midst of chaos where ~150 objects are bouncing around the screen, the transforms matched exactly on both platforms!
Here is a video where everything is 100% synced between my Nexus 5 Android and PC by only sending the player's input state: http://youtu.be/RhseAgPSWUA
After seeing how well it worked out, I decided to try another simulation, this time having a stack of rectangles on top of each other and shooting a sphere at it. Anddddd....... that's where it starts... After setting up the stacked up rectangles, I did a quick simulation to see how it syncs on my network. The results did not match on both platforms =( This seemed strange to me as in my other simulations with about 150 objects bouncing and colliding, both simulation were 100% synced between both platform. But... having little bunch of stacked up rectangles results in different simulation in each platform :s
So I did bunch of tests, I played around with _controlfp_s to try to match Android's Java floating point precision but no luck there since as of right now I have no idea how Java rounds floating numbers. I wrote a script to make sure that objects in Unity are created in the same order every time, but that doesn't seem to be the problem - though, I feel that I may of missed something and maybe objects are not being created in same order.. O ensured all multi-threading is disabled..
However, the simulation always matches on all my Android phones. My PC always produces the same simulation each time, but the simulations are different on each platform. Unfortunately, it seems to be the floating point precision problem that many developers run into =(
My main concern is maintaining deterministic across Android and iOS devices. I am hoping there is a work around this.. Is there certain things I should avoid to maintain determinism? for example, avoid physics that rely on transcendental functions(sin , cos, etc..)?? Also is there any hope if I switch to BEPU double version? - will that help? What about fixed-floating number?? - my game is not a physics game, so I am not concerned about the quality of the physics.. Is there any suggests that you can give me that could point me to the right direction????
Once again, thanks for this great engine, I will surely donate if my app does well in app market.
First off, I would just like to thank you for making this amazing engine.
I have played around with it for few months now and basing my upcoming multiplayer app on it.
I am currently developing a game for Android and mobile iOS devices. I am using Unity3D and BEPUphysics .Net 3.5 v1.30.
Initial I used the physics engine to run on my server and had great results syncing players by just sending the transform of the objects. However, the main problem with this model is latency, bandwidth and having to run the physics on my server for each game. Since from playing around with BEPUphysics, I learned it is pretty good at being deterministic, so I decided to program a lock-step version of my network. It turns out that it works out really well and very responsive.
After some initial testing of syncing my PC and Nexus 5 Android, everything seemed to sync really well between my PC and android. Even in midst of chaos where ~150 objects are bouncing around the screen, the transforms matched exactly on both platforms!
Here is a video where everything is 100% synced between my Nexus 5 Android and PC by only sending the player's input state: http://youtu.be/RhseAgPSWUA
After seeing how well it worked out, I decided to try another simulation, this time having a stack of rectangles on top of each other and shooting a sphere at it. Anddddd....... that's where it starts... After setting up the stacked up rectangles, I did a quick simulation to see how it syncs on my network. The results did not match on both platforms =( This seemed strange to me as in my other simulations with about 150 objects bouncing and colliding, both simulation were 100% synced between both platform. But... having little bunch of stacked up rectangles results in different simulation in each platform :s
So I did bunch of tests, I played around with _controlfp_s to try to match Android's Java floating point precision but no luck there since as of right now I have no idea how Java rounds floating numbers. I wrote a script to make sure that objects in Unity are created in the same order every time, but that doesn't seem to be the problem - though, I feel that I may of missed something and maybe objects are not being created in same order.. O ensured all multi-threading is disabled..
However, the simulation always matches on all my Android phones. My PC always produces the same simulation each time, but the simulations are different on each platform. Unfortunately, it seems to be the floating point precision problem that many developers run into =(
My main concern is maintaining deterministic across Android and iOS devices. I am hoping there is a work around this.. Is there certain things I should avoid to maintain determinism? for example, avoid physics that rely on transcendental functions(sin , cos, etc..)?? Also is there any hope if I switch to BEPU double version? - will that help? What about fixed-floating number?? - my game is not a physics game, so I am not concerned about the quality of the physics.. Is there any suggests that you can give me that could point me to the right direction????
Once again, thanks for this great engine, I will surely donate if my app does well in app market.