0
\$\begingroup\$

I have a multiplayer game done with Phaser, which runs in the browser and on a node.js server.

The server is authoritative, every 50ms or so it sends the game state object to all clients. The clients receive the state and update all instances accordingly. The game runs at 60fps, and the physics and AI are the same on clients on server, so if there is no user interaction the game will evolve exactly the same (the next frame on the server will be equal to the next one on the client). This should make sync much easier, but I have a problem:

When the client receives the state from the server, the state is no longer up to date (as there is the latency between server and client).

Here is a drawing:


Server: State1 -> State2 -> State3 -> State4 -> State5
................................................*-------------------V
Client : State1 -> State2 -> State3 -> State4 -> State5State3


So, when the client receives State3, it is no longer usable as it has already been at State3. This makes the game always rewind a few frames when it receives the update from the server. How can I solve this, taking in account that the same game engine runs on both client and server (so prediction is much easier).

I would try "rendering the game in the past" as I have seen in other cases, but I do not really think I can break Phaser physics/render loop connection.

\$\endgroup\$
11
  • \$\begingroup\$ does the new state from the server overwrite the current client state? or do you "ease in" the new state. say, a position. if you ease it in, latency shouldn't be too visible. \$\endgroup\$
    – oberhamsi
    Commented Mar 17, 2015 at 19:11
  • \$\begingroup\$ That's the problem, because I am using Phaser with the p2js physics engine it would be harder to implement my own interpolation. I was just asking if there is somehow possible to start the client game a few states later, so when it receives State3 it actually has to be at State3 (not State5). And yes, for now the client state is over-written by the server state when it is received. I have fixed some issues by not over-writting the state if the state is close enough (this is similar to prediction being close to actual position). \$\endgroup\$
    – Cristy
    Commented Mar 18, 2015 at 8:21
  • \$\begingroup\$ @Cristy , did you achieve any progress? \$\endgroup\$ Commented Feb 17, 2016 at 15:29
  • \$\begingroup\$ @unknown.0perator I haven't worked on this game that much since this question was posted, but as far as I remember, the game was running pretty smoothly because I made it interpolate to the current position instead of teleport to it (slowly move to the position received from the server) and once it reaches there it extrapolates until the next state is received (the physics engine kicks in and moves all objects with the same logic that exists on the server). \$\endgroup\$
    – Cristy
    Commented Feb 17, 2016 at 15:49
  • \$\begingroup\$ And this question is actually a bit misleading, as once the client receives "State3" the next states he will receive will actually be usable and should usually match the current client state. So, the game on the client would actually look as the game on the server, but with a small delay, given by the latency. \$\endgroup\$
    – Cristy
    Commented Feb 17, 2016 at 15:52

0

You must log in to answer this question.

Browse other questions tagged .