Jump to content

Handling physics in a multiplayer game


Recommended Posts

I'm starting out learning to build games in Phaser and doing multiplayer games and had the idea that I would build a simple multiplayer game to play with the kids. the basic idea:

Two teams of either 1 or 2 players each kick a ball around a bounded area trying to get it into the opposing teams goal.

I've played around with the physics engine demos a little bit and think I know enough to make a player (circle) that can move a ball (another circle) around in a Phaser game using P2 physics.

I've also messed a little bit with node.js and the sockes library and implemented a little demo of setting up a server for multiplayer.

Now I have gotten to the question of how to handle the physics in a multiplayer game. It seems to me like the physics simulation should be running on the server but how do you do that? Do I run a Phaser instance on the server to simulate physics or do I choose a standalone physics library and run that on the server?

Bonus question: If physics is being simulated on the server do I need to run any physics on the client in this multiplayer example?

Link to comment
Share on other sites

  • 11 months later...
  • 1 month later...

The ideal way would be to do both.  If the client is interpolating movement then it will not appear gittery with lag.  Most likely you will have to write your own system for this.  I am also researching the same and will post my results.  Perhaps there is a phyics engine that does both client and server side.

Link to comment
Share on other sites

  • 3 weeks later...
On 3/21/2018 at 5:25 AM, CocktailFriend said:

Do I run a Phaser instance on the server to simulate physics or do I choose a standalone physics library and run that on the server?

Personally, I would do neither.

A Phaser instance on the server is overkill. From my understanding, you only need simple 2D collision detection (circle-circle, circle-rectangle, rectangle-rectangle, etc.), and simple physics (2D vectors, trigonometry, etc.). Phaser will add so much weight to your server (i.e. use up memory) meanwhile you'll only use a fraction of it.

A standalone physics library is overkill. Again, you only need simple physics and collision detection.

Why not try writing your own implementation on the server?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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