How to do group voxel system

Hey everyone its the voxel destruction physics guy here. So Ive been tackling this issue with group voxel systems and I’m totally stumped I have no clue how to make it work and on top of that I need it to be able to detect when a voxel splits from the group.

If anyone out there has any ideas on how to tackle this I really appreciate the help! I’m feeling pretty lost right now Thanks in advance!

(if you need any info any me like voxel type or idk)

Do you mean when you have a bunch of voxels, and through destruction the voxels split in a way that a new separate ‘island’ of voxels is created?

Or do you mean when you have a bunch of physics-enabled voxels that are welded to each other, you want to detect when the weld between them breaks?

it the island one so in the image the main part that is not separate has a group id of 1 when it split one side keeps the ID of 1 and the other side gets an ID of 2

For that, you’ll have to query the voxels in your terrain to identify separate islands. In your server script keep track of a 3-dimensional array - a table inside a table inside a table, representing the X, Y, Z indexes of the voxels like so:

-- Auto-generate this nested table when you generate your voxels in the world
-- (Or compile your voxels into this table if you're using pre-designed maps)
local voxels = {
     [1] = { -- X
          [1] = { -- Y
               [1] = { -- Z
                    voxelData, -- this may be a reference to the voxel part in the world
               },
               [2] = {
                    voxelData,
               },
          }
     },
}

Then you will index specific voxels based on their position within the voxel grid like so:
local specificVoxel = voxels[X][Y][Z] – where XYZ is the index of the voxel.

When a change is made within the voxel world (when a voxel is destroyed or created) you shall loop through the voxels, checking which voxels are attached to each other. You’ll have to do a little research on pseudocode for an efficient enough algorithm on how to handle this. While this isn’t something I have experience with, this appears to be the algorithm that you’re looking for :smiley:

my solution is completely different for your I used flood fill to detect if there more than 1 clusters and just select the first cluster as that one to get new id but thx a lof I couldn’t think of a solution until I see your post and it give me idea :smiling_face_with_three_hearts:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.