How to add Collision Detection to MultiMesh Instances?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By LemonSqueezy


I’m new to Godot and Game development in general.
I’m trying to build voxel-/block-based, editable terrain (for simplicity sake, think of it like minecraft). I want the player to be able to view far into the terrain.

I first tried creating the terrain with every block being a StaticBody (with MethInstance and CollisionShape). Starting at around 20.000 blocks the performance went down dramatically.

Now I’m using MultiMesh instancing and the performance for drawing the blocks is incredible. But I don’t know how to add collision shapes / collision detection to the MultiMesh instances (so in this case my player character falls through the terrain).

My current solution is to create separate StaticBodys that hold all the collision objects (in this case BoxShape) for the meshes. Keeping track of the collision shape and the mesh separately seems tedious to me, especially when editing the terrain.
Also I have been hitting some performance issues when creating a lot of collision objects (basically the same issue as my first attempt).

Things I already thought of:

  • I could only instantiate collision object close to the player (within the radius of interaction, e.g. gun shot range), but again, this seems tedious.
  • I could combine collision objects, thus reducing the amount of collision objects, but again, this seems tedious.

Is there a more efficient / scalable / performant way to assign collision shapes to MultiMesh instances ?

Any help would be greatly appreciated :slight_smile:

:bust_in_silhouette: Reply From: Antoine Goutenoir

I’ve had the same question for Octron Mania, and I dug a bit.

Short answer : make one static body, add many shapes to it.

There may be some more perfs to gain by crafting one complex shape ; not sure.

See [SOLVED] How set collisionShape on MultiMeshInstance? - Archive - Godot Forum