Jump to content

Phaser 3 - synchronisation with server


undisputed
 Share

Recommended Posts

Hi,

I'm trying to make synchronisation (WASD movement) for MMO game. I read these tutorials: http://buildnewgames.com/real-time-multiplayer/http://www.gabrielgambetta.com/client-side-prediction-live-demo.html and this is what I got:

Client:

-player is sending movement info to the server in the update method

public update(time: number, delta: number) {
      if (isPlayerMoving) {
            var info= {
                    up: this.cursors.up.isDown,
                    down: this.cursors.down.isDown,
                    left: this.cursors.left.isDown,
                    right: this.cursors.right.isDown,
                    timestamp: Date.now(),
                    movementSequenceNumber: player.sequenceNumber++;
            };
            ..
            if (isMovingLeft) {
                player.setVelocityX(100);
            }
            ..
            socket.emit('movement', info);
      }
}

Server:

-authoritative

-there are 2 loops (first for physics - position update 60 fps, second for broadcasting other players)

-saves received movement inputs from players and then process them in physics loop

 

That would work if the both client and server are running on same frequency (like in those tutorials - there's fixed loop on client). But in Phaser 3 update loop might lag so the delta time is not always 16.67, but it can be higher. This is a problem because physics is still running on Phaser so the player is moving faster than he has to (or the server is moving too slow?). I'm not sure what should I do because if I change the update method just to update the position (not velocity), I would break FPS independency..

 

 

So the question is:

How and where should I tell the server that the player is moving? Isn't the update method the right place for it?

 

 

Link to comment
Share on other sites

Personally I handle logic separate from Phaser, using it just for the rendering. What I use is a combination of update and my own setTimeout to move the game logic forward and send inputs to the server. Basically this, except I have 2 entry points (both RAF, i.e. Phaser's update, and my own timer).

On top of that is interpolation of other entities, prediction of player's entity and syncing time with the server.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...