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
@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?
@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.
@gbz Thank you so much! I will look into this.
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:
- Get Node.js as an exe
- Use the subprocess module python has. In other words, run the node js.
- 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.
I think another option is to use REST or GraphQL for Interprocesscommunication, depending on the Game.