What's the basic approach to making a complicated level with physics collision?

Hey everyone, I’m new to babylon and trying to make a basic game with some characters walking around and fighting. I have a level I cobbled together in Blender and exported to glb, then imported into a babylon scene. Now I want to make my characters not able to walk through walls and random objects around town, but I’m having trouble finding info on the right way to do this.

It seems like the way to go is to use this work-in-progress plugin (and its corresponding Babylon-side plugin) but I’m wondering if there’s a more standard approach I should take. What are more experienced Babylon devs doing when they want to import a level with a lot of stuff going on?

Hi @CodeMonkey welcome to the forum!

Yes, it’s still WIP. Until it’s ready for production, the approach I use is to code the physics setup. Basically get the meshes by name, create shapes and bodies and set constraints.

1 Like

I would start simple. Load all your meshes, then per mesh

  • try PhysicsAggregates with ShapeType.MESH first
  • if that kills frame rate, try ShapeType.CONVEX_HULL
  • if that kills frame rate, see if you can live with even simpler shapes

If you can get away with this, there is next to no extra work. Otherwise, well, I do it like this: For complex meshes, I create custom bounding boxes (per mesh). If no bounding boxes present during game loading, I use ShapeType.BOX for that mesh. Works pretty well in my case.

You can also do dynamic setup where you only activate physics for near map chunks (if the game type allows it).

1 Like

For simple collisions you may even don’t use Physics at all - https://playground.babylonjs.com/#0VHCTL#220

3 Likes

Thanks everyone, all three of those answers worked great. I’m using the rigidbody exporter plugin with Blender for now, but I’m probably going to regret it soon since I just picked a random non-finalized build, haha. I didn’t know the mesh collider or the built-in collisions were an option, those are great too

1 Like

I use my ground mesh as it is, and all the other complex meshes have simplified collider meshes, or just created with code (capsule for characters, box for most of physics objects like a chair for example)

1 Like