Tl;dr: How can I run playcanvas with physics on a glitch server (with nodejs)?
So I was following the playcanvas multiplayer tutorial (here) where you set up a glitch server to relay player position data. However, I found that calling rigidbody.teleport() all the time to keep all the entities in sync was really slow. I wanted to see if I could run all the playcanvas physics serverside and have each client transmit player input (keypresses). Then, I could take all the physics off the client side and have the server tell all the model components on the client side where to go.
So I tried downloading playcanvas and ammo onto the glitch server and immediately ran into two problems:
Playcanvas seems to require the DOM to run correctly
I donāt know how to āimportā the playcanvas code into server.js
Is there a better way of getting physics to be in sync for all the clients? If not, is there any way to run playcanvas physics in a nodejs environment?
@yaustar Iād rather avoid using ammo.js directly if possible, I like that playcanvas provides a nice level of abstraction away from it as it seems the documentation for ammo isnāt that great.
@mikefinch Yeah thatās basically the idea, all the physics would happen on the server and all entity positions would be sent to the clients.
Otherwise, you can use another physics engine like cannon.js or oimo.js
Ideally, it would be best if there was a deterministic physics engine with a fixed timestep so it could work on both client and server with corrections every now and then.
I believe there should be solution for that. It should work internally, sync states between all the clients.
I donāt think we should write it from scratch.
You can hit me up on Skype midgardh Iāll send you a zip with an example of a websocket server running in nodejs with the PlayCanvas engine included. I did it very dirty but it works and you can have the server running a playcanvas scene, with entities, components, physics, etc. Then just send the entityās position to the clients. Pretty simple stuff.
Hey, sure, Iāll set up a github repo this week. Maybe we can work together to get it more well tested and cleaned as my implementation is pretty dirty :ā)
Thank you very much @devMidgard. I tried using nodejs but I couldnāt create a pc.Application without a valid canvas, so I tried using JSDOM but got an āunsupported browser exceptionā. Please let me know when you get that github repo set up .
@yqu In theory it should work, but I still havenāt been able to actually test it. It seems like the only viable solution though, otherwise each client instance will be calculating the physics a little bit off from the others.
To be honest and fair, Itās simply far more intuitive and easy to build mutiplayer games with the same tech on client&server.
PlayCanvas just makes it ultra comfortable to work with. Adding components, creating new entities, handling scenes⦠itās just the good shit! And having all of those features on server side is super super handy.