Sign in to follow this  
undisputed

Phaser 3 - synchronisation with server

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?

 

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.