Architexture question, how should I implement collision to my voxels?

Godot Version

4.7

Both GDScript, and C++ with GDExtension.

Compatibility renderer enabled just for web export.

Question

I’m currently working on a Minecraft-y block game, one feature that’s important is blocks can be physical objects in the world so the player can build their own vehicles, I have most of the rendering and voxel managing figured out, but I don’t know how I should approach getting objects to interact.

My current method is generating a concave trimesh for my StaticBody3D chunk grids. (For chunk grids that are set up to be a RigidBody3D physics object I use simply a convex shape.) This is good because using the native physics engine works fine, and it means it’s easy to just use move_and_slide() in the player(the player is a cylinder CharacterBody3D).

However I am personally not a fan of this, I don’t like generating a new trimesh for every chunk, it’s slow and dumb, if an object falls though the hollow “skin” of the world it will fall forever instead of hitting a block inside, if a chunk is out of render distance entities won’t be able to touch it. I would prefer if I could have a custom solution instead that just samples the voxel data itself to act as if each block has an independent collider. Firmly decoupling rendering from physics, freeing up memory, and removing any need to preprocess collision.

The problem is, I have no clue how to implement this new physics body feature in the slightest.

  • Can it be integrated into Godot itself with GDExtension, or should I custom build my own physics up from scratch?
  • If I can use the existing physics, should I be using Godot Physics, Jolt, or Rapier?
  • Do I need to handle every situation of collision between every type of collider (eg cylinders and convex shapes), or are there some shortcuts?
  • What about scale and rotation?
  • Can it work for mobile rigid bodies as well as static bodies for the ground??
Class tree for reference
# Level
#   |
#   L ChunkGenerator
#   |
#   L ChunkGrid
#   |     |
#   |     L ChunkRenderer (Cpp) <- this is where all mesh gen happens rn
#   |     |
#   |     L Dictionary[Vector3i,Chunk]
#   |     |                      |
#   |     |                      L PalettedVoxelGrid (Cpp)
#   |     |                               |
#   |     |                                L VoxelGrid (Cpp)
#   |     |
#   |     L ChunkLoader (static)
#   |           |
#   |           L (file system)
#   |
#   L LevelSaver (static)
#         |
#         L (file system)

TLDR: I need to create a new type of collider for my block game, how do I figure out the architecture?

Let me know if I’m understanding you:

you’re generating a mesh that is the exact shape of the chunk. But this is slow because it requires frequent regeneration + if an object somehow makes it past the surface it will keep going without colliding with any other blocks beneath.

So then obviously for some reason you don’t want to use a cube collider for every voxel. (Maybe it would be hundreds or thousands?)

Have you considered a hybrid approach?

EG larger, pancake shaped colliders for the layers beneath the surface + individual cube colliders for the blocks on the surface level.

I guess I could hack around it by creating real collision, but if feels like a waste when it’s easy to read the blockdata.

ok I think I see what your saying. You have the voxel data, and then you have the physics body which is sort of like duplicate data and you want collapse those two into one.

IDK if that’s really possible. You either have to make optimized use of the existing physics engine (physics only near the player, use object pools, clump voxels into large blocks when possible) OR use a vastly simplified physics system that you make yourself.
How much physics do you have going in block game?

If I remember right, Minecraft uses a really simple physics system. Like as in blocks can only move in voxel increments. So if an object gets moved by an explosion it has to move into a new block position. But an actual physics engine uses floating point world space. Those are two pretty disparate systems. So yeah I’m not exactly sure what you’re trying to go for here but if you’re using an actual physics engine inside of a voxel based world they’re going to have to be totally separate and their interactions will have to have strict rules for interfacing with each other. I can’t think of any easy way that you would combine them into a singular system