It is pretty much what the question says. I have a multiplayer game only for PC. It works fine in LAN, but when player using internet, it lags too much. Especially the position of the player changes properly in my system, but in the other player’s system, it looks like blinking from one place to another.
The game is pretty simple maze like game, the player has to move around and collect some objects and environment is pretty much empty. Only pickups and players are synced.
Everything else is completed, or at least that is what I thought and I got this problem. Please help me.
To answer your question on player blinking, well there is no proper way of fixing it. Because it depends on the ping from one player to another and Unity uses UDP (in a modified way)[read more on UDP from this page ] which is unreliable so in case of packet loss, it is inevitable to do anything. Every game lags in a way or another.
But this can be fixed by tricks.
A simple approach to fix the blinking to an extend is by predicting where the player would move to next and move the player locally and then correct the position of the player with the value that comes from the other end.
For example player moves in direction x,y,z at a speed delta.
[ the speed can be locally calculated using player positions from different frames. When a change in player position is noted save the time frame (Time.time or Network.time) in a temporary variable and the position as well (use a temporary variable to check for change in player position.) Then calculate the difference in time and find the difference in positions (distance).Divide distance by time you have the speed.]
Direction can be found using the tranform.Forward in most cases (sometimes it changes coz of model), if that doesnt give you proper output, try getting difference between the old position (the position you use for getting speed) and new position and normalize it to get direction.
Now you have both speed and direction, manipulate the movement locally and move it every frame. Dont worry about this thing disturbing the original position coming from other player because Datasynchronization and serialization will set the position back to the actual value, if it changes also.
I hope this is clear.
Also regarding your scene setup, it looks fine for me and there shouldn’t be any lag for this small setup. How much is it lagging? is it playable?.
Anyways to optimize it,
Try to avoid too many RPC calls.
Check if the state synchronization on network view is set to reliable (unreliable takes more data usage).
I cant find anymore ways where it might go wrong for you.