MoveTo delta speed and online timing

So I’m making an online game with socket.io and phaser and I run into a little problem:

Everything moves faster on PC while android devices lag behind.

I use game.physics.arcade.moveToObject to move to a waypoint but the same problem occures with moveToXY and other methods.

Here is logic:

Two players are on the map in the same X position but different Y positions.

Player one on PC clicks on a location to the right a few pixels and starts moving to right on both screens of PC and Android device.

Player one arrives to desired location earlier on PC while still moving on Android.

Movement implemented with constant speed of 32 in update scope if player’s current position is not equal to corresponded player’s waypoint which is updated via websocket signal from server.

game.time.advancedTiming is set to true and desiredFPS to 35. This did help but only a little.

How should I approach this? Is there such a thing as delta speed? I could also periodically update player’s location that server would keep track of but last time I checked there was no phaser module for node.js, so I can’t really calculate player’s location serverside.

How should I approach this? Is there such a thing as delta speed? I could also periodically update player’s location that server would keep track of but last time I checked there was no phaser module for node.js, so I can’t really calculate player’s location serverside.

First of all, if you want to avoid cheaters in your game, you must implement an authoritative server architecture, where the server is the only source of truth for all the clients and validates all the client inputs. The client then is just dumb representation, rendering received state from the server. This way, you must run the game simulation on the server. As you already noticed, there is no Phaser module for node.js, so you will need to implement all the logic yourself. I believe there were some attempts to run phaser in headless mode, but I didn’t find any working example. (Can someone correct me here please?)

I can recommend you to go through following articles that in-depth describe the authoritative client-server architecture and many concepts that make multiplayer games possible:

https://antriel.com/post/online-platformer-2/ - Making multiplayer platformer with Phaser and Node.js.
http://www.gabrielgambetta.com/client-server-game-architecture.html - Client-Server game architecture
http://buildnewgames.com/real-time-multiplayer/
https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization - This one is more complicated but still a must-read for anyone interested in multiplayer game networking.

Player one arrives to desired location earlier on PC while still moving on Android.

I believe it happens due to latency. Player one pressed move button and starts moving → sends it’s input to the server → server broadcasts it to another player → second player start rendering ‘player one’ movement(while on ‘player one’ screen it already started some time ago). This issue is basically inevitable, the player will always see other players moving in the past, and your player is moving in the present.

1 Like

I think @artvinn is suggesting the right path to investigate.
You might also find your answer from this article and examples.
Playout Delay Buffer

I have investigated the possibility of latency but it wasn’t the issue - android browsers (firefox and chrome) really do perform worse. Their PC counterparts don’t have this issue - players move at relatively same speed but lag behind due to latency and not the perfomance of moveTo method while mobiles have both.

Anyways I’ve already started implementing @artvinn 's suggested architecture, although partially - server is responsible for keeping player’s movement in check and not the whole physics engine for various reasons (laziness mostly :wink: )

Thanks for great suggestions

Try with

game.forceSingleUpdate = false;
game.forceSingleRender = false;