Using three.js, how can I set up a headless version on a node server like the babylon.js-NullEngine?

I have been working towards creating a multiplayer three.js fps game and am planning to only do client-side prediction in the browser. On the other hand, I use Node.js Express.js and for the authoritative server-side implementation of the multiplayer game and would like to check collision server-side.

Using three.js or external libraries, what are the possible options to create a headless version of the game state like the babylon.js-NullEngine and calculate raycasting collision on the server-side?

Similarly, how do multiplayer io-based games keep track of game states server-side and do bullet and movement collision?

1 Like

I haven’t tried what you describe, but I know that many parts of Three.js, notably geometry definitions and raycasting, are independent of the renderer. The built-in raycasting is very inefficient, though, since it does not index static geometries.

1 Like

As Elias mentioned above - many parts of Three.js are independent of the rendering process. That means you can install Three.js the same way you install (I personally prefer the lower level of ws). Then you create a THREE.Scene of your world, initiate the necessary geometries (or simplified versions) for the game.
Add listeners to sockets on user input and update your gamestate based on those.
Use setInterval() loop running 60 times per second (since thats the maximum amount of frames your players will usually get with requestAnimationFrame() ). You can perform your necessary calculations there, server-side, and send update packages to all clients.

That is my suggestion :slight_smile:
Such games are a very broad topic and I’ve seen there are many books on it, as well as some cool tutorials/courses online.

1 Like

Hard core FPS players may object to that. I think it may be fast enough to be convincing, though, as long as you don’t tell the players about it. :wink:

1 Like


Thanks for all the fast responses. I am pretty new to three.js.

How do you initiate geometries serverside? They are not of type Object3D. They have no worldMatrix properties. Using three.Mesh objects seems ineffective. What are the simplified geometries mentioned?

THREE.Mesh does not have to be ineffective. The materials are compiled during first render, which in your case will never happen, so you can have a dummy material there that does no harm. Just make sure you update the transforms on every timestep, like the renderer would do.

1 Like