Open valkyrienyanko opened 5 years ago
Update
Clients only send data if their moving over a minimum difference for each movement update. Server only adds data of client if that client has moved to all other clients.
Obviously this improved performance drastically.
I have what might seem like a silly question, I have 4 clients each sending position xyz updates to the server every 100ms and the server sending all the player position data back to each and every client also every 100ms.
When there are 2 clients, everything is fine. When a 3rd comes in, the server or clients (don't know which) can't seem to keep up with all the updates and lag behind until all the clients eventually timeout.
Note that position updates are sent even if the same values exist. (E.g. if a client is staying still on the server, they are still sending the regular updates). So all clients are "moving" all the time.
What exactly is causing the timeout / lag?
Client
The client uses this built in Unity function to send data to the server. Position updates of the client are sent to the server. https://github.com/valkyrienyanko/Networking-Unity-Prototype/blob/0f0bf7ea4c90bbd04765f53a340f3c121233756a/Client/Assets/Scripts/Client.cs#L228-L245
The updates are sent every SEND_DELAY seconds. https://github.com/valkyrienyanko/Networking-Unity-Prototype/blob/0f0bf7ea4c90bbd04765f53a340f3c121233756a/Client/Assets/Scripts/Client.cs#L219-L226
Server
The server uses this built in Unity function to send data to the clients. https://github.com/valkyrienyanko/Networking-Unity-Prototype/blob/0f0bf7ea4c90bbd04765f53a340f3c121233756a/Server/Assets/Scripts/Server.cs#L193-L198
Position updates are sent to the clients from the server every SEND_DELAY seconds. https://github.com/valkyrienyanko/Networking-Unity-Prototype/blob/0f0bf7ea4c90bbd04765f53a340f3c121233756a/Server/Assets/Scripts/Server.cs#L51-L87