I'm trying to handle all the physics on the client and correct data on the server.


Client_1 wants to move right
Server broadcasts that
Clients simulating Client_1's movement
Client_1 sends it's coordinates to the server (every 100ms)
Server validates coordinates based on client's last position and last update (which is stored on the server)
Server corrects Client_1's coordinates on every client

But when FPS<60 players are moving faster than they should, which causes server to teleport them back.

My question is basically how to check x,y without teleporting players with high latency (or low fps).


var now = Date.now();
var clientX = ...x position sent by client...
var clientY = ...y position sent by client...
var timeDiff = Math.ceil((now - player.lastPositionUpdate)/5)*5;
var timeDiff = timeDiff > 1000 ? 1000 : timeDiff;
var pixelPer100 = player.speed/10;
var maximumPixelDiff = (pixelPer100/100) * timeDiff;
player.lastPositionUpdate = now;

if (clientX > player.position.x){
    var diff = clientX - player.position.x;
    newX = player.position.x + (diff > maximumPixelDiff ? pixelPer100 : diff);
..and more


update: function(){
    player.body.velocity.x = player.speed;
    if (tick == 6){
        tick = 0;

I'm using Phaser with Arcade Physics.



You must log in to answer this question.

Browse other questions tagged .