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:

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 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() {
    for (input in savedInputs) {
          player.y += input.down * speed;
  • \$\begingroup\$ Have you considered decoupling your game simulation step from your rendering framerate? (a la "Fix Your Timestep") There's no particular reason the server should need to care about rendering details. \$\endgroup\$ – DMGregory Mar 18 '18 at 23:00
  • \$\begingroup\$ Server is definitely not caring about rendering. The question is how the server reach same same result as client (on player y position) \$\endgroup\$ – dontHaveName Mar 19 '18 at 7:17

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.