Theory on how to make a multiplayer game

This is an idea I just thought of (like just today).

If you have a babylon.js project running, then a website, you could make a multiplayer game.

How it could work:

You have the game running with no cameras, but a function that can make one. When a user connects to the site, a window.alert(); could pop up asking for a username. The input would name a canvas “username-canvas”.

Somehow (I thought this up today, haven’t thought this through) the function that can make cameras is triggered, adding a camera, connected to “username-canvas”, and control would be given to “username-canvas”.

That’s the basic idea. Not sure ho keydown, keyup, mousedown, mouseup events would work.

I wonder if something like this would work with sites like github, gitlab, or bitbucket.

Feedback would be nice. Just an idea.:wink:

1 Like

Ive been using PubNub free tier to do my websocket handshake to connect users via webRTC, which I plan to use for p2p communication of player/world state, so as to avoid a centralized server and associated overhead.

1 Like

If anyone has a readymade solution for webrtc game state transfer id love to see it.
Seems as close as it gets to UDP

I also thought of another idea.

Running the game in the server can’t be done with a static hosting site. But I think I have a solution.

The first person to go to the site will be the “host”. They will run the game and others will connect to the host. If the host leaves than another person will run the game. Limit of 4 people maybe?

Because it is static everyone will connect to the same site, and run the game at the same time. Only 1 person will have everyone else connected to them.

Just a thought.

@withADoveInOneHand I’m making a multiplayer game and any pre-made webrtc solution would be great for me too.

Right, I think you want every client running the game logic, and everyone shares a world state.

It’s not webRTC but why not use something like Colyseus Multiplayer Game Server for Node.js?

1 Like

I think I would be able to use Colyseus with my original idea.

Have the server run the game, and when someone connects, it makes a new camera and adds control. I gotta try that!

Thanks for the suggestion.

I would use but I didn’t know Colyseus and it looks like a great candidate !

1 Like

Thanks for the suggestion! I should really make a list. I’ll have to try out so many game server options!

@Givo You can also try Nengi.js which was built for 3D browser based games. The author is pretty active and he has a discord channel where you would get pretty good help. He also has a demo using Babylon js and the library has features like Latency compensation. You can check out his videos on youtube as well for things it can do.

He is the author behind Nengi js


Wow! I gotta try this one first! The latency is low, and this guy also made, a game I’ve played with my friends before. Thanks for the suggestion! This one is at the top of the list!

Current list:

  1. Nengi.js
  2. Colysues
1 Like

Yeah i guess running my own xmpp/socket server would be best. My AWS guy is always swamped though ×p I bug him too much.
Running an unordered p2p webrtc data stream will still need an ice/stun/turn server though… Which who knows how to set up.


I’m to cheap for that. That’s why I use gitlab and heroku.

Right, and it’s no walk in the park. Never tried gitlab (git io is slick though), heroku pay tier was… not a great bargain.

Gitlab is like github, but it has an amazing Web IDE. Have you tried heroku free tier?

Gitlab’s Web IDE:

Oh yeah that looks real straight forward. Free tier did treat me well, i just wouldnt marry my architecture to it (or any pay service for that matter, guess thats common sense)

Oh. I might have to host my own sever then for my game.

Yeah, Gitlab is pretty simple. Did I forget to mention that you can open many files at once?

1 Like

Oh yeah a web ide is something i gave up looking for, will have to take it for a spin.

Definitely recommended, 8.5/10! (1.5 taken off for the web IDE not being the default editing thing in gitlab)

on a repository you have to click the web ide button!

1 Like

:heart: The 411 :facepunch: