Hi, I’m trying to replace AmmoJS with cannon-es in my project. I’m using this cannon-es example
and at this point I’m stuck with how to get the vehicle to be shown in the scene?
My (not working, I mean it’s working but it’s not adding the body to the scene) code so far:
The examples in the cannon-es are using Three.js. I checked that they are using some demo.addVisual function, which uses bodyToMesh function. So I guess I should do something similar and create BabylonJS meshes?
I think probably @Cedric is the person that may give me some hints
Thanks in advance!
The general idea is - after the physics is done calculating the next position, update the babylon meshes corresponding the impostors. for example, in the postStep event in cannonjs, iterate over each impostor and “copy” its transformation to a babylon mesh you have already created
that seems to be causing a fight between babylon’s physics loop and the cannon changes, no? You are using babylon’s phyiscs impostors on the wheels, and then update them in the postStep again. Do you need the physics impostors? or better - do you need the physics engine plugin in this case?
This kind of hybrid solution would require a lot of playing around with the babylon cannon plugin and special configuration to the impostors.
You want to avoid transforming your meshes twice. either the babylon physics engine is doing it (as in my example), or youa re doing it manually (and then you don’t need enabling the babylon physics engine. I will be happy to find time and show you a simple example of this way of working, but i won’t make it today, that’s for sure…
No problem! I’m also done for today. Thank you for your help - it really opens new doors in my head
So when you wrote about the physics engine plugin you meant the Babylon impostors?
If so - I think I won’t need it. I want to build simple car racing game with heightmaps so I will need Cannon plugin - it should do all the work.
(I switched the camera’s position). There seems to be an issue with the force application. This might be the version of cannon we are using over the version of cannon this was developed for. It is possible that cannon-es has fixed a but (or added params), that are not supported in the old cannon implementation. that’s probably why steering is not working as you expect.