Search code examples
synchronizationlatencymultiplayerroundtrip

Do good multiplayer/mmo client<>server games use latency within movement calculations?


There's a couple of questions here.

Imagine I have client A who's going to send the following message to Server: "START MOVEMENT FORWARD".

The server will not receive this message instantly, as there is a delay because of latency.

Question 1: ping (or better: round trip time) is the amount of time it takes for the client to send a message to the server and receive a response back. Does this mean the following if you can ignore the time it takes for the server to notice that it has received a message and start sending a response (this should be very short)?

  1. time it takes for client to send someting to server = round-trip-time / 2
  2. time it takes for server to send something to client = round-trip-time / 2

So, when client A sends that message, the server will supposedly receive that message round-trip-time / 2 milliseconds after the client has send the message. This leads me to the next question.

Question 2: should the client first send the package, and then wait round-trip-time / 2 milliseconds before actually executing that command client-side (in this case: move forward) to compensate with the latency/lag?

Now, the server will send the following message to all nearby players: "CLIENT A IS NOW MOVING FORWARD". These clients will then make sure that the character of client a starts moving, this leads me to the next question.

Question 3: should the client receiving the message that an other client has moved take into account that this message was send by the server round-trip-time / 2 milliseconds ago? So that the current time used for movement calculations timestamps should be reduced by round-trip-time / 2?

All these methods would in my mind make sure that synchronisation improves between clients, as latency is taken into account. Is this the right way of doing things? Do most other good multiplayer games do this? Any comments, suggestions, alternatives or random but related shouts that you'd like to give? Thanks in advance.


Solution

  • I think that in most mmo's your client mainly moves without interaction with the server unless bad lag occurs. The server reproduces the movement with the help of the messages the client send to the server. So if for example the server lags, the client will stop recieving feedback from the server and revert to the position the server determine that you are at. That is why you jump back several frames during bad lag. This way the server will also have control over your speed so that you are not speedhacking. If your client moves at a certain rate which is over the speed determined by the server, you would simply jump back the extra frames.

    Other clients would not let you move at all without response from the server within a certain amount of time. This is the times you would experience 'freeze-lag'.

    Of course there are also occurences where the server simply take the position sent by the client and blindly trusts it. These are the games that are generally vulnerable to teleport hacks.

    When it comes to the position of other players there indeed is a delay, which can be seen if you take two computers, connect to a game such as wow and move the two characters simultaniously. You would see that on both computers the non-local character will start moving after you really started moving him.

    The client usually have some sort of lag compensation. So if another player is moving at a certain direction and then stops, your client will still simulate the movement of that player until you recieve a message from the server that he changed direction or stoped moving. That is why other players can jump back and forth when the ping is high. This is also why players can seem to just slide/run/walk away when you hit lagspikes and then return to their real position when your clients recieve positions from the server.

    Of course this changes from engine to engine but it's a rather general aproach.

    Edit: Forgot to add that it is very common for the server to also use lag compensation. If you hit someone in a mmo that is in range of you, that person might not be in range from the servers view. So the server takes the latency for both your clients and tries to match up if you were really in range of eachother or not.