Hello,
I've been wanting to design a game with a destructible voxel world with physics. I want there to be a custom voxel world, and explosions will take out voxels. Easy. The hard part is preventing floating chunks of voxels (meaning voxels that are not attached to the ground). I have created a demo of the voxel function, but it has a few flaws that I will talk about later.
But here is essentially how I went about designing this demo. All the voxels initially have physics, but have 'immovable' checked in order to prevent them from moving and keep performance acceptable. When there is an explosion, all voxels in a certain range get 'immovable' unchecked and impulse away from the explosion. Then a voxel update is called.
When the game is called to update the world, the game first set s all voxels 'IsOnGround' instance variable to false, then checks to see which ones need to be true. It first checks all of the voxels connected to the ground and sets their 'IsOnGround' to true. Each of these checks the four positions immediately around it, and if there is a voxel in those positions, the process is repeated for each of them. This is visualized in my demo by the red and blue colors each voxel is set to. This works very well, although it is somewhat slow as not to overload the computer.
The part I have trouble with is collapsing the voxels that still have their 'IsOnGround' variable to false after the check. The only way I could think of is having a sprite check each row a few seconds after the update check is called. When the sprite overlaps a voxel, it checks the voxel to see if the voxel's 'IsOnGround' is true or false, collapsing the voxels that are false. This sprite is the red bar that moves across the screen in my demo.
This works but has a few issues. It is slow, as floating voxels will not be collapse until a few seconds after the update. The other issue is that when dealing with complex shapes, the checking may not have time to complete before the sprite comes and collapsed voxels. The final issue is when explosions occur before the first explosion checking is complete, which could mess up the whole system.
Here is the demo file: https://www.dropbox.com/s/9889wxtjayvdyhv/Voxel%20Physics.c3p?dl=0
Do you have any ideas on how to collapse the voxels that are not attached to the ground?
Thanks in advance,
Give me a Pixel