I asked the same question at Unity forums but I wanted to get the ideas of you guys also to have an idea out of Unity.
We are working on a multiplayer pool game heavily based on Unity physics (PhysX) and we managed it have a stable version of the single player gameplay.
For one week, we are working on the multiplayer version of it. Firstly I can say I am not a networking or physics expert but I know all the concepts of them, have 3 years background in game industry and have made a long research about it before I came to here.
Our current solution was the easy one which turnout to be not that easy. It is sending force direction and position from clients and calculating physics on both client/server and correcting the results (supposed to be too low) from the server at the end of the turn. To be able to make this work, we have made lots of investigation:
Firstly; simulation wasn't even same at the same computer with the same executable. To be able to correct it, we have to work on many Unity parameters, we corrected it up to same extent but none of them worked perfectly.
Our final results with break shot for 15 + 1 balls:
Client, two same shots, three balls position:
Ball_1: 7.647239, 1.791727, -7.450733
Ball_1: 7.647166, 1.791727, -7.450527
Ball_12: 3.079326, 1.791727, -3.05286
Ball_12: 3.080814, 1.791728, -3.052271
Ball_15: 7.133366, 1.791727, -11.65263
Ball_15: 7.133381, 1.791727, -11.6526
Server, two same shots, three balls position:
Ball_1: 7.649154, 1.791727, -7.458591
Ball_1: 7.649155, 1.791727, -7.458614
Ball_12: 3.076369, 1.791727, -3.062551
Ball_12: 3.076268, 1.791727, -3.063016
Ball_15: 7.1292, 1.791727, -11.64938
Ball_15: 7.129121, 1.791728, -11.64801
As you see the results are very close now but still even 0.01 differences make significant differences at some points (with a strong force or situation like in the client ball enters pocket but in the server it doesn't with a very small difference and such..).
I know the main problem here is physics random numbers and floating point arithmetic but I still believe there could be a workaround for this as it is a turn-based game at the end.
So my question here: Is it possible to make Unity physics deterministic and make it work with this approach?
Only way for this is state sync from server to clients which uses bandwidth around 6kB/s per player (16 balls, 12 bytes for position, 16 bytes for rotation, 10 bytes for header). Down side for this is; it will very expensive when we reach huge amount of players, also connection speed could effect this a lot.
Writing our own stable physics for it. Down side for this is; production cost and optimization issues. Possibly we could use another physics library with Unity but not sure if it will worth the results.
I hope someone could lead me to a possible solution for this.
Thanks in advance
Members - Reputation: 130
Posted 20 September 2013 - 02:59 AM
Members - Reputation: 340
Posted 20 September 2013 - 01:15 PM
I don't know myself, but I've heard a couple of people claim that deterministic physics isn't possible with Unity.
Deterministic physics is a very attractive way of making a multiplayer physics game send very little data. I'm doing this, but I have my own physics code, so when it breaks it's my own fault
Crossbones+ - Reputation: 1342
Posted 23 September 2013 - 06:01 AM
This may not be what you want for your game, but one approach you could take is to have the physics simulation take place only on the machine of the player whose turn it is, and simply transmit the positions of the balls to the other player. This solves your problem (I think) but it also makes scaling the solution easier. For example, if you decide at some point to have multiple observers of the game, transmitting the results is a straight-forward extension of transmitting the ball positions to the opponent. This comes down the idea that there is only ever one source of the Truth in the system and everyone is an observer (until it is their turn of course).