Jump to content

phaser real-time mmo authoritative server


dontHaveName
 Share

Recommended Posts

I'm trying to build a real-time MMO game. I'm using Phaser for FE and Node.js + socket.io for BE. I have read all the tutorials like http://www.gabrielgambetta.com/client-side-prediction-server-reconciliation.html and so on.

Different players might have different FPS, this is how I update position on the client (phaser):

const data = {
  down: this.cursors.down.isDown,  
  timestamp: Date.now() 
}; 

var deltaTime = (data.timestamp - this.lastTimestamp) / 1000;
if (data.down) {
    player.position.y += speed * deltaTime;
    socket.emit('input', data);
}

This ensures speed is FPS independent (every player is moving with the same speed).

The server is running a tick() at 60 FPS. This method is processing saved inputs from players. How should the server correct player positions? It doesn't know their delta times. It also can't use server's delta time since it would be always around 0.016 and it doesn't reflect player's update interval.

tick() {
    var now = Date.now();
    var serverDelta = (now - this.prevTimestamp) / 1000;
    this.prevTimestamp = now;

    for (var player of players) {
        player.update();
    }
}

player.update() {
    for (input in savedInputs) {
          player.y += input.down * speed;
    }
}
Link to comment
Share on other sites

Why does the server need to know a players deltaTime? My understanding is that it is just broadcasting positions and maybe speed (which is FPS independent).

The client has to take care then that the difference between expected and corrected position does not look awkward (I've seen people using tweens to do that).

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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