VoxDestruct | Voxel Destruction Module


Introduction

Hello, I made this cool module that allows you to make holes in parts but with voxels :wink:. It is basically a voxelizer that can handle lots of voxels in your destruction game, or if you just need voxels for an explosion.

This module uses octree division and also greedy meshing and ObjectCache for ultimate performance. It works for hundreds of holes in your game before you even start lagging a bit. It also provides some useful functions that will help you with your needs, such as it can cleanup voxels in the world if you are doing a map reset. It stores a lot of the parts before hand, then moves them in when needed which provides the trick of instancing new parts, while itā€™s not.

image image image


Example

Here is an example of a AK-47 and a AK-47 Shotgun (yes), that can create holes in parts. As you can see, you can adjust the voxel size for different types of weapons.

I have adjusted the voxel size to be pretty small here.


The script itself isnā€™t too complicated. Thought it does have many features! You can adjust multiple things such as voxel size, debris amount, ignore lists and more. Currently, it does not support square hitboxes, or wedges.

The module comes in the name of ā€œVoxManagerā€, which will handle most of the creation for you. If you need a lot of customizing, you can call Voxelizer.subtractHitbox yourself in the Voxelizer module located under the main script.

Any feedback would be appreciated, and I will try to add more to this. Right now, I feel it is pretty easy to add your own new stuff to it, such as breaking sounds and changing debris sizes and other things.


Downloads:

Module: https://create.roblox.com/store/asset/90280745196148/VoxManager


API

VoxManager:voxelize(hitbox, minimumVoxelSize, finalVoxelSize, randomColor, debris, debrisAmount, ignore)

Info:
Pass in a sphereical part, and anything itā€™s touching it will destroy and become voxels.

Parameters:

Hitbox - A part of type Enum.PartType.Ball
MinimumVoxelSize - A number, the minimum voxel size. 2 is recommended.
FinalVoxelSize - A number, when the calculations are done, voxels will try to go to this size. Recommend this should be the same as MinimumVoxelSize .
RandomColor - A boolean, debug coloring, shows the divisions on the part.
Debris - A boolean, whether there should be debris.
DebrisAmount - A number, the amount of debris per subtraction.
Ignore - A table of parts to ignore in the hitbox calculation.


VoxManager:voxelizePosition(position, radius, minimumVoxelSize, finalVoxelSize, randomColor, debris, debrisAmount, ignore)

Info:
Pass in a position and radius, and anything in that area will be destroyed and become voxels.

Parameters:

Position - A Vector3, where the subtraction will take place.
Radius - A number, the radius of the subtraction hitbox.
MinimumVoxelSize - A number, the minimum voxel size. 2 is recommended.
FinalVoxelSize - A number, when the calculations are done, voxels will try to go to this size. Recommend this should be the same as MinimumVoxelSize .
RandomColor - A boolean, debug coloring, shows the divisions on the part.
Debris - A boolean, whether there should be debris.
DebrisAmount - A number, the amount of debris per subtraction.
Ignore - A table of parts to ignore in the hitbox calculation.


VoxManager:cleanup()

Info:
Cleans up all voxels in the world.


VoxManager:setDebrisSize(multiplier)

Info:
Sets the debris size, relative to the destroyed part hole. Recommend 0 - 1.

Parameters

Multiplier - A number, the size relative to the destroyed part.


Are you thinking of ever using this?

  • Yes
  • No
  • Iā€™ll definitely use it later for other projects.

0 voters

7 Likes

Looks dope! I dunno if you know but:

Looks promising!
Also, Iā€™m not sure if itā€™s worth it, but have you considered using ObjectCache instead of PartCache?

Well, I did need a replacement to VoxBreaker.

  • You should consider using ObjectCache.

  • We should be able to have debris amount based on the part that got destroyed.

  • I assume youā€™re using GetPartsInPart. (I am unable to check currently) This is less performant, and I recommend using GetPartsBoundsInRadius instead. If you arenā€™t, you should just let us pass in the GetPartsBoundsInRadius arguments ourself instead of needing to create a part on the spot.

Iā€™ll look into ObjectCache. It doesnā€™t actually use GetPartsInBounds or anything of the sort.

All distance checking and math is done in the code, so itā€™s a lot more performant, since itā€™s a direct function I made.

1 Like

Thanks, I made it public now. Hope you like it.

1 Like

Instead of passing a part, can we pass a size and position? or is that a nah

You mean radius and position? I can implement that.

1 Like

Yeah, thatā€™s what i meant

What do you mean by get the debris amount based on the part that gets destroyed?

Automatic debris amount based on the size of the part destroyed, I donā€™t really know how to explain it. It should use the volume of the destroyed area to create the debris I guess?

I thought about that, but I didnā€™t want to create too much debris as that can be laggy. Also, itā€™s not to o hard to go in the script and change the minimum debris size to be more relative to the block destroyed size.

If anything, you can probably make it optional. is it possible to make the minimum size dynamic? Iā€™m so dumb lmao

Itā€™s already dynamic, it gets the size of the part, then adjusts it to be smaller. Though I can include a :SetDebrisSize function?

2 Likes

Yeah, Iā€™m an idiot lmao. If I have more feedback, Iā€™ll tell you.

Small Fixes and Small Update V.01

  • ObjectCache is now being used.
  • setDebrisSize() function to set the debris size relative to the partā€™s size.
  • voxelizePosition() function which can voxelize parts a specific position, given a radius too. This removes the need of creating a hitbox yourself.
  • Fixed small bugsā€¦
1 Like

Hey! Iā€™m loving this so far and I wanted to request some features.

  1. Can you add a paramter for regenerating the lost parts after a timer? (Or just restoring the part to its previous state)
  2. Can you provide some example code because my debris system is glitched (debris size is incorrect and is destroyed instantly)

Thanks!

EDIT: I modified your script (Thank goodness itā€™s light) to fix the debris thing but Iā€™m a bit lost on the regeneration, would be appreciated if you could figure that out.
(I just added a speed and duration paramter to :voxelize)

3 Likes