Hello!
Some other users have posted similar issues, but I was wondering if I was going about this problem in the wrong manner.
Quick simple run down of the situation. I have a football (or Soccer if you must ) game, with two teams against each other.
Each team has 5 footballers that can be controlled, either by real people (users) or AI if uncontrolled. At ANY POINT during the game, a user can switch which character he is controlling with the AI, so can swap around to be nearer the action ect (not with other users mind, so no AI players means no switching).
So I have a footballer prefab, with a FootballerController script running on each one, this takes input and sorts out movement, actions like kicking ect, either an AI could fire off commands or user input.
I was synching this data up with an OnSerialzeNetworkView function within the script, serializing the transforms and game state that I need.
The issue I have is, who ever is the server creates the whole initial gamestate, so is classed as the âownerâ of all the players as they exist regardless of the number of users, and so is the only one who can write state (BitStream.isWriting being true).
The other clients can move their footballers, but they donât stay in sync as they are never writing the state. The server player can move his character and it appears in sync on all clients as he is writing state fine.
I really like the idea of the OnSerializeNetworkView method and being able to put what data I want to sync and be happy that that is happening, can I just change the âownerâ everytime a user changed who they are controlling? Is there another way to sync state without the owner being an issue? Are RPC calls the only real solution? If so would it be foolish to link up an RPC call to all input the user can do, every time they fire off a message to the FootballController script also fire of an RPC (this would happen every time the keystate changes or there is a mouse click)? What about reconnecting/midway joining, I need a way to sync state, but then I guess the Server who owns it all can send thatâŚ
Ok that last paragraph got away from me a bit. Is the solution for all users to use RPC calls to move their players on their machine AND on each other? Would it work like so, clients input movement, call an RPC call on their footballer, that is sent over the wire, moves the player on the server machine, which then calls the isWriting section of the OnSerializeNetworkView, or is the OnSerializeNetworkView now only needed for reconnects/midway joining?
On an unrelated note, does âUnityâ in any way do anything to resolve conflicts? Is there any documentation on âhowâ the networking works under the hood, UDP?, TCP?, is there a guarantee that the RPC call will arrive, what about a laggy/late packet, how is that resolved on a client, if at all?
Any thoughts are much appreciated!
-Iain
(I might be away from my computer periodically, so sorry if I donât reply promptly but I will try and keep an eye on this thread)