Flask Web Server with Babylon JS collision detection

I am using flask in order to host a babylon js webserver. I use babylon js for the clients. I want to detect collisions from the server side. My question is does anyone know how to use babylon js for collision detection with python? I don’t need anything to be rendered. Thanks in advance.

Hello and welcome!!

This is why we have NullEngine: Server Side - Babylon.js Documentation

2 Likes

@DeltaKosh Thank you! However, is there any way to implement this in python 3.8?

Hey @trigangle! Would you be open to using Node.js on the backend/server? If so, you could try something like:

Client:

  • BABYLON.Engine
  • Use WebSocket to communicate with server

Server:

  • BABYLON.NullEngine
  • Communicate with client using ws

Having the client and server code in the same language can help a lot, especially if the same (physics) simulation will be run on both client and server.

Is there a reason why you plan on using Python 3.8 instead?

2 Likes

@gbz I want to use python 3.8 because I have written a lot of code in it as well as I already have a server that is hosted with it. Howver, If I can integrate a js server into the python server, that would be great.

Ah I see, I haven’t tried integrating Babylon with Python before, so a more experienced user would have to answer that.

Would highly recommend looking into Node.js express. The only code you need to have your server serve an index.html web page is:

import express from 'express';
const app = express();

app.use(express.static(__dirname + '/client'));

app.listen(80, () => {
	console.log('Listening on port 80...');
});

// Your physics simulation with BABYLON.NullEngine here and your ws WebSocket code

assuming that your index.html is in a folder named client in the same level as the .js file with the code above.

1 Like

@gbz Thank you so much! I will look into this.

1 Like

I have found a solution. I am posting this here so that future programmers who want to build a 3d game using babylon and flask can use this:

  1. Get Node.js as an exe
  2. Use the subprocess module python has. In other words, run the node js.
  3. Simply run the babylon code you want to.

This has worked really well for me as I can now make a functional 3d multiplayer game.

1 Like

I think another option is to use REST or GraphQL for Interprocesscommunication, depending on the Game.