1
\$\begingroup\$

I'm prototyping an online fast paced multiplayer game for educational purposes. I use a client-server model with the server being authoritative.

I've already implemented the client side prediction based and it works fine. Now i'm working on the entity interpolation, i'm using a simple algorithm:

interpolationTime = currentTime - INTERP_BACK_TIME //for my game 0.1s for INTERP_BACK_TIME
state1, state2 = getTwoInterpolationStates(interpolationTime) //get two states to interpolate between

length = state2.Time - state1.Time
t = 0.0

if (length > 0.0001) t = (interpolationTime - state1.Time) / length

entityPos = state.pos

entityPos.lerp(state2.pos, t)

This algorithm works fine if the server sends only correct states, which is not the case of my server, let me explain why:

The client sends what i call Actions to notify the server about what he is doing. For example, if the client press the right key, it will send a new action to the server, something like MoveAction(1, 0) to tell the server he is moving right. If the client keep pressing the right key for 5 seconds, the client will send only two actions, MoveAction(1, 0) at t = s and MoveAction(0, 0) at t = s + 5. I'm testing the whole thing with a ping of 150ms, so the server receive actions 150ms late.

Here is what happens on the server when the client presses the right key for 5 seconds (there is 150ms ping between client and server):

  1. MoveAction(1, 0) is received at t = s (s is the time on the client)
  2. The action starts being processed on the server (the player starts moving to the right until a new action is received)
  3. MoveAction(0, 0) is received at t = s + 5
  4. The server knows at this point that the action (MoveAction(1, 0)) has ended and lasted 5 seconds on the client (but on the server it lasted 5 seconds + 150ms since the MoveAction(0, 0) is received 150ms late)
  5. The player then need to be snapped back to his correct position

The step 4 is actually the one causing me problems for the interpolation. Since the actions are received 150ms late, the player will keep moving right for 150ms on the server (after the action is completed on the client) before being snapped back to his correct position when the action finally arrives. My server sends game snapshots every 20ms so it will potentially sends 7 game snapshots with incorrect player positions.

How should i deal with this scenario? Should i avoid sending this kind of invalid states or should i handle them client side?

\$\endgroup\$
  • \$\begingroup\$ I'm no network savvy, but maybe you could make your client 'lag' on the reception of the MoveAction(1, 0) so that it take into consideration that it will arrive 150 ms late. The idea would be to delay the start of the action instead of repositioning it at the end. I'm not sure if this makes sense at all.. :P \$\endgroup\$ – Alexandre Vaillancourt Sep 25 '15 at 15:32
  • \$\begingroup\$ What do you mean by 'on the reception of the action'? The client does not receive the action. Could you be a bit more descriptive? : D \$\endgroup\$ – nathan Sep 25 '15 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.