jodo

Multiplayer Test with NullEngine()

Recommended Posts

Hi Guys! I haven't been active here for quite some time and haven't done anything with Babylon.JS for quite a long time. But after checking out the changelogs, I saw that we can now run Babylon.js Server Side, how awesome is that!

So I had to squeeze in some time and implement a proof of concept multiplayer simulation with Client and Server side physics engine. It's quite basic. The Client can control a ball by spinning it forward or backward (with W and S). By changing the camera angle (with A and D) you can change the direction of the impulse. With Space you can jump around. To check out how it behaves with multiple players you can either ask someone to also visit the site at the same time or just open a new tab in your browser. 

Technical it is rather simple. Server and Client communicate via Websockets. The client applies impulses to it's ball, these parameters for these impulses are sent to the server. The server applies these also and keeps the state for the whole world up to date. Each render loop the server sends the current state to all the clients (ideally 60 Hz). The clients then correct the position, direction and velocity of all objects including their own ball if needed. I haven't tried it out with higher delays, but I would suspect the result will be quite "jumpy". Interpolation for correction and prediction of movement is not (yet) implemented. 
Added Server Update Rate and Ping to see lags and delay in perspective to these metrics. 

Here is the code: https://github.com/j-o-d-o/multiplayer-babylon-js-game

Here is the Demo: http://185.82.21.82:8700/

 

Here is a great article about Server-Client Game Networking techniques: http://www.gabrielgambetta.com/client-server-game-architecture.html which was somewhat the motivation to implement this proof of concept.

multiplayer_game.png

Share this post


Link to post
Share on other sites

Well done! I tried this a couple years ago, but I ran cannon.js separately on the server (at that time I don't think there was any Babylon.js implementation on the server). I see that you are using Oimo.js which should perform a bit better than Cannon (with the cost of less features). At the time, once I had >6 clients joining, the game becomes very laggy (even including interpolation). I see that the same also happens in your demo. Do you have any plans to tackle this issue? I couldn't figure it out and thought that it was simply the physics engine :P.

Looking forward for more updates!

Share this post


Link to post
Share on other sites

@Threedy Yeah, the server side NullEngine() just came out with v3.1 about a month ago (according to the 'what's new.md' file), so you had a much much harder task 6 month ago ; )

I haven't got time yet to go into detailed performance debugging. But I would say it is a network problem and not a physics engine / simulation issue. 10 objects are definitely no problem at all for the physics engine, even on bad hardware. There is almost no CPU used on the Server, but pretty much all of Memory is allocated. (Also, other small test applications are running on it). And it is a really small server (just 1GB of RAM). I am not a network specialist, but I assume decreasing the server update rate could help as well as decreasing the size of each update message. 

When 10 users are connected, all RAM is used and there is about 800kb/s outgoing traffic. You can see that the ping stays pretty much the same for the first few connections and at some point, just skyrockets to 2000 ms and higher. I assume TCP packages start getting lost while 10*60 new packages are Queuing up per second which quickly stacks up to such a high ping. (Someone please correct me in case I am talking garbage here) ; ). 

I also assume (yes, lots of assuming here) that using UDP would decrease the network problem, but as we know, it isn't possible with browsers. 

Share this post


Link to post
Share on other sites
5 hours ago, jodo said:

@Threedy Yeah, the server side NullEngine() just came out with v3.1 about a month ago (according to the 'what's new.md' file), so you had a much much harder task 6 month ago ; )

I haven't got time yet to go into detailed performance debugging. But I would say it is a network problem and not a physics engine / simulation issue. 10 objects are definitely no problem at all for the physics engine, even on bad hardware. There is almost no CPU used on the Server, but pretty much all of Memory is allocated. (Also, other small test applications are running on it). And it is a really small server (just 1GB of RAM). I am not a network specialist, but I assume decreasing the server update rate could help as well as decreasing the size of each update message. 

When 10 users are connected, all RAM is used and there is about 800kb/s outgoing traffic. You can see that the ping stays pretty much the same for the first few connections and at some point, just skyrockets to 2000 ms and higher. I assume TCP packages start getting lost while 10*60 new packages are Queuing up per second which quickly stacks up to such a high ping. (Someone please correct me in case I am talking garbage here) ; ). 

I also assume (yes, lots of assuming here) that using UDP would decrease the network problem, but as we know, it isn't possible with browsers. 

Hmm you're right. I most likely have messed up something there.

Anyway, looking forward to your project and hopefully more updates!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.