I’m trying to set up collisions with an imported model that has a “ground” and a “track” mesh. However, it’s not quite working as expected. The problem is that if I move my camera towards the ground it seems to go “through” the ground and stay just underneath it.
I’ve got a playground showing the problem here:
I’ve tried to do a bit of searching around on this problem and there are two things that come up. The first is issues with glb/gltf imported meshes and collisions not of “rigid bodies” not being respected - I don’t think that’s my issue here as I’m explicitly setting up collisions for the relevant meshes. The second seems to be around pivot points of the mesh not matching, but if I check ground.position and ground.getPivotPoint() the both show (0, 0, 0) (well, getPivotPoint() shows (-0, -0, -0) but I don’t think that’s a problem is it?).
No, no reason not to be using that besides not being familiar with what I should use. Will take a look and see how far I can get, starting with Babylon.js docs.
I’ve looked into it a bit more, and it seems this could be quite involved…
I have large models with complex terrain (the one in the playground looks pretty much flat but it isn’t totally flat - most other models have a lot more hilly terrain). It looks like the approach I’d need to take is to create a physics shape for each object that I want to add to the physics engine. The docs for “shape” (Babylon.js docs) seem to suggest a HEIGHTFIELD (which I think is what I’d need for a complex terrain) isn’t supported by the v2 plugin, but then there is a playground example here that uses it, linked off the same doc page: https://playground.babylonjs.com/#I37D8G#18
Can anyone confirm if this is supported (happy to update the docs in a PR if so)?
Assuming it is supported, it seems I’d need to choose the number of subdivisions I want to support rather than just being able to use all of the height data from the ground mesh that I’m creating externally (in Blender), which could be arbitrarily complex? The use case is motorsport race tracks from the real world, so I’m hoping I wouldn’t need to be limited to a certain size. Typically the models are about 2000m x 2000m in size, would like to be able to be accurate to at least the nearest meter. Does that sound feasible, or should I look at another approach?
Er, sorry, noob question here, but what do you mean by that? I’ve tried creating a sphere, marking it as not visible and then parenting it to the camera in this playground, but it’s not working as expected (in that the camera can still go through the ground): https://playground.babylonjs.com/#849YCW#7
My camera now seems to be affected by gravity (which is good), but it’s still falling through the ground (very slowly because I’ve dialed down the force of gravity to give me time to enable the PhysicsViewer): https://playground.babylonjs.com/#849YCW#9
When I enable the PhysicsViewer I can’t see any difference in the scene at all (possibly my mesh is too big for me to see anything?).