Jump to content

Phaser multiplayer P2JS interpolation


tips4design
 Share

Recommended Posts

I am using Phaser P2JS for a multiplayer game which receives the state of the game from an authoritative server once every 300ms.

 

The same game engine runs on the client, so before the next state is received the game extrapolates the current state (simply runs the game from the last known state). When the new state is received I update the positions of the players based on what the server sent me. Is there any simple way of integrating interpolation in the transition towards the new state, without affecting the P2JS physics caluclations.

 

Current State1 -> Extrapolate -> Receive State2 from server -> Interpolate towards State2 -> Current State2 -> etc...

 

So, from the above pipeline I want to make sure the interpolation between two states (eg Player.x = (Player.x + Player.newX) / 2) won't break the P2JS engine.

Link to comment
Share on other sites

I have partially solved this problem by simply doing the interpolation methond mentioned above: Player.x = (Player.x + Player.newX) / 2 

I do the above computation in the update loop of the player, making sure to only interpolate small enough distances (if the distance is greater than MaxInterDistance, constant defined by me, then it will simply jump to that position).

Link to comment
Share on other sites

Thanks, but I read a lot about interpolation and network games, the problem was this specific implementation with Phaser and P2JS. I didn't want to break the physics loop somehow while directly setting positions for bodies. It turned out that everything works well, even though I directly set positions to bodies from time to time.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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