Jump to content

Has anyone made a multiplayer Babylon.js game?


ozRocker
 Share

Recommended Posts

I'm trying to make a multiplayer game and I'm struggling to even get a ball moving forward on key-press.  I can't get client prediction and server reconciliation done properly.  This is because the latency from server receiving key-down instruction is different to the latency from later receiving the key-up instruction.  So on the server the ball is moving forward, the server gets an instruction from client that key is released and server goes "Oh sht!  That packet took so long to get here, the key was released 1 minute ago.  The ball has moved too far forward!  X should be at 8, but it kept moving forward because it took so long to receive the key-up instruction that its now at 11."  I don't know how to deal with these cases apart from shifting position when the ball stops moving.  Does anyone have an example of a Babylon.js game that handles this properly?  Every tutorial I've seen on the net only deals with single key-presses instead of key-down/key-up sequences.

Link to comment
Share on other sites

i m "converting" one to babylonjs. It was a sloooowww old flash game that i stop few years ago.

multiplayer game is possible with node.js and socket.io

you if you try to be "keypressed" responsive... you will give users the ability to spam too many broadcasts. So you will have to script an anti-spam test :P

if you realy need this it's possible, and easily done with soket.io. Just send start order "keydown" with a broadcast and keayup with an other one.

You can complete the broadcast with start and final position (and client time).

I would probably use an other way:

For your exemple, every client could give his position every 1 seconds broadcaster to others ones and controled by server.

client should "animate" the moves of enemies between 2 updates.

Server side control (nodejs): server should evaluate the move from player. is it not too fast and is it possible.

you can use statistic control to reduce stress (controle maybe 10 moves every 10 seconds ^^ and kill if not correct :P)

it's less responsive but maybe enought to play ^^

 

 

 

Link to comment
Share on other sites

8 hours ago, iiceman said:

Well, I remember this post:

Not perfect but seems to work okay for a first try. Whats your basic setup? Node.js an socket.io?

I had a look at that guys code.  He's not using an authoritative server for his multiplayer game.  He's sending player positions and rotations to the server, instead of sending keypresses and getting the server to evaluate position and rotation.

I'm using a C# back-end for my socket server, using the Fleck library.  Its faster and more accurate than Javascript and very easy to implement.  I'm using standard websockets for my Javascript client.  All that works very well.  I am doing what @eboo is suggesting by sending when the key is pressed down and then when the key is released.  That's only 2 instructions that get sent to the server.  I'm not sending position information because I'm using an authoritative server.  Since this is javascript its very easy for people to change their position and cheat so its important that only server evaluates position.

I understand prediction and latency.  The problem is when you have changing latency.  The client presses key down to walk forward then releases 10 seconds later.  So he is walking for 10 seconds.  The server will receive keypress and will start walking.  What happens is the instruction to stop walking does not arrive exactly 10 seconds later.  Sometimes it arrives 12 seconds later.  So the server has been moving the player too far forward.  It realises this when it eventually gets the key-release instruction and sees its timestamp, so it has to make a correction to jump back a bit.  This is the part that I'm not sure how to handle.  I don't want to have my player jumping back at the end of every walk.

 

Edit: I have a feeling that I shouldn't even be sending a timestamp, because client could change that to say "That key was pressed 2 minutes ago" which will make the server jump the player very far forward.  I've read somewhere that you need to continuously calculate latency and use that to determine when the event actually happened on the client

Link to comment
Share on other sites

I liked this very good article on writing multiplayer game in HTML5 : http://webcache.googleusercontent.com/search?q=cache:-k_6smmA7YwJ:buildnewgames.com/real-time-multiplayer+&cd=1&hl=en&ct=clnk (it's a cached page, unfortunately buildnewgames.com is down)

It uses socket.io and NodeJS. I know you use a C# server but the logic should be the same, it's talking about game loops, client prediction, interpolation..

Link to comment
Share on other sites

1 hour ago, Pouet said:

I liked this very good article on writing multiplayer game in HTML5 : http://webcache.googleusercontent.com/search?q=cache:-k_6smmA7YwJ:buildnewgames.com/real-time-multiplayer+&cd=1&hl=en&ct=clnk (it's a cached page, unfortunately buildnewgames.com is down)

It uses socket.io and NodeJS. I know you use a C# server but the logic should be the same, it's talking about game loops, client prediction, interpolation..

Yep, I've read that one and all the articles mentioned in it.  They are all dealing with single key-press scenarios which is much simpler than time-based key-presses.

I think I need to change my code so the client sends a key-down event with every update-loop.  This will cause net traffic (depending on how frequent the update loops are) but dealing with time-based keypressing is too inaccurate.  If a client pressed UP for 50 milliseconds they will move a little bit on their screen, but if the server is waiting 500 milliseconds to get the key-release event then the server will move the player 10 times are far is he should be!  However, this problem is not so bad if the player keeps finger on key for a long time

Link to comment
Share on other sites

  • 4 months later...

*bump*

ozRocker, I struggled with this too. What you need to do is the following:

On a key press and hold, record for instance 5 impulses. Apply them on the client side and send them to the server. However, keep a small sort of cache on the clientside of this list. (This is important ill come back to this in a bit)

The server then applies these forces (5x up e.g.). It collects those too and sends them back to the client. On the client side, you loop through this list and delete them in chronical order. If something does not match, fix the position and forces of the client according to the server.

Link to comment
Share on other sites

2 hours ago, AutoSequence said:

*bump*

ozRocker, I struggled with this too. What you need to do is the following:

On a key press and hold, record for instance 5 impulses. Apply them on the client side and send them to the server. However, keep a small sort of cache on the clientside of this list. (This is important ill come back to this in a bit)

The server then applies these forces (5x up e.g.). It collects those too and sends them back to the client. On the client side, you loop through this list and delete them in chronical order. If something does not match, fix the position and forces of the client according to the server.

Thanks for the info.  I've managed to implement that system already.  You can see it working at www.punkoffice.com/webiverse

Link to comment
Share on other sites

Hello @ozRocker -

All of the advice above is good. And in my opinion, the best solution (and one you'll be VERY happy discovering) is to use node.js as you can thread many operations and use WebsocketIO to keep connections open. Take a look at some of the existing code available for node.js and you'll find everything you need. Pay close attention to "rooms" as this provides discreet abilites and security. We are dynamically exchanging allot of events btween a massive number of users including the syncing of media - but there are rules as the media must exist on the server and then stream to each user to maintain sync. However the exchange of mult-user events requires 20ms to 30ms for collaborative drawing and editing of media on average through most all routing we've tested. I wish I could explain further, but we're under strict utility patent guidelines, and can't expose what we do on the server. But what you're attempting is already written and you can find online.

The following is a bit dated, and you can replace Express of course, and jQuery might be a good fit for you, but we're using our own API on the server side. Once the API is up to spec and less exposed, we'll release, but we're looking at 2017.

http://modernweb.com/2013/09/30/building-multiplayer-games-with-node-js-and-socket-io/

DB.

Link to comment
Share on other sites

3 hours ago, dbawel said:

Hello @ozRocker -

All of the advice above is good. And in my opinion, the best solution (and one you'll be VERY happy discovering) is to use node.js as you can thread many operations and use WebsocketIO to keep connections open. Take a look at some of the existing code available for node.js and you'll find everything you need. Pay close attention to "rooms" as this provides discreet abilites and security. We are dynamically exchanging allot of events btween a massive number of users including the syncing of media - but there are rules as the media must exist on the server and then stream to each user to maintain sync. However the exchange of mult-user events requires 20ms to 30ms for collaborative drawing and editing of media on average through most all routing we've tested. I wish I could explain further, but we're under strict utility patent guidelines, and can't expose what we do on the server. But what you're attempting is already written and you can find online.

The following is a bit dated, and you can replace Express of course, and jQuery might be a good fit for you, but we're using our own API on the server side. Once the API is up to spec and less exposed, we'll release, but we're looking at 2017.

http://modernweb.com/2013/09/30/building-multiplayer-games-with-node-js-and-socket-io/

DB.

Thanks for the info @dbawel  I've already built the framework and its up and running at www.punkoffice.com/webiverse I'm using C# as the backend with websockets to communicate with the clients.

Link to comment
Share on other sites

Hi @ozRocker - I was wondering why this topic appeared again. As you know I've been to your site and was very impressed - also to meet you in your own world. C# will serve you very well, however node.js has so much flexability and code already available, that I would take another look - at least in the near future - especially for threading processes and partitioning users. Once you generate your initial framework and design in node, maintinence will be much easier to manage, as well as adding features. I'm looking forward to where you take your free roaming world, as I've yet to see anyone else as ambixious, yet already online.

Cheers,

DB

Link to comment
Share on other sites

I considered nodejs and I'm still keeping an eye out.  I chose C# because I read that its faster with CPU intensive operations.  Also I was inspired by openSIM which is in C#.  I personally prefer C# to javascript because its a more powerful language and offers strict type system and compile-time error checks.  Its also easier to manage the growing codebase in a project that could end up quite large.  I haven't come across any situations where there's something I can't do in C# which can only be done in nodejs.  That being said, I'm constantly checking both technologies to see if there are any major advancements and listening to feedback from other's experiences with both frameworks.

Link to comment
Share on other sites

I'm not that familiar with openSIM, as it had limitations when we considered LSL/C# maybe 5 years ago. I assume for your purposes, you can run what you need by a factor of 10+ for processing physics, collisions, etc. What you're currently building is beyond my current skill set, as I was using C# when it first moved into .Net. Wow, I didn't realize it was that long ago.:mellow:

Again, looking forward to watching your world grow.:)

DB

Link to comment
Share on other sites

yeh openSIM is kinda old, so I can't really say "I need to use C# cos that's how its always been done" 'cos I realise that's a bad reason to stick with a certain framework.  They're probably stuck with the language they started with.  I can't say for certain what the best framework is for what I'm trying to do so I'm constantly researching to find definitive answers.  I'm looking for clues like "I HAD to switch to node.js/C# because there was no way I could've built this feature" or "I used node.js/C# because the other language couldn't handle the bandwidth or computations required"

Check these guys out https://www.facebook.com/groups/1500317060224340/

Cosmos3D is a new webGL virtual world currently being built.  It has so many features it looks like an IDE.  It was initially built using the Virtual World Framework.  Its a framework using node.js and three.js that sets up websockets and 3D graphics for networked 3D scenes (apologies if you already know it).  They got pretty far with it then had to completely switch because that VWF framework couldn't scale up to a large number of avatars.  I'm not sure what they are using now though.  They even stopped using Three.js (maybe they're using Babylon.js instead?)  

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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