VoxelDestruct | Voxelated destruction physics with greedy meshing, hitboxes, and more!

Hmmmm what about slice feature? So that I can use it for cut any part that use metal material only for lightsabers like from Star Wars movie series.

What does lock, freeze and other stuff does? Edit: Nevermind I am stupid

I am making API to smoothly migrate from VoxBreaker to this module! Will release soon(ok it will take more time)

1 Like

Wrote it like in 3 minutes…

--Not done
local RunService = game:GetService("RunService")
local Signal = require(script.Parent:WaitForChild("VoxelDestruction"):WaitForChild("Signal"))
local Settings = require(script.Parent:WaitForChild("VoxelDestruction"):WaitForChild("Settings"))
local VoxelDestruction = require(script.Parent:WaitForChild("VoxelDestruction"))
local VoxBreakerAPI = {}
local Hitboxes = {}

function VoxBreakerAPI:CreateHitbox(Size : Vector3, Cframe : CFrame , Shape : Enum.PartType, MinimumVoxelSize : number , TimeToReset : number, Params : OverlapParams)
	local debris, walls = VoxelDestruction.destroy(Cframe, Size, Shape, Params, MinimumVoxelSize, math.huge, nil, false, TimeToReset, false, false)
	return debris
end

function VoxBreakerAPI.CreateMoveableHitbox(MinimumVoxelSize : number, TimeToReset : number, Size : Vector3, Cframe : CFrame , Shape : Enum.PartType, Params : OverlapParams)
	local Hitbox = Instance.new("Part", Settings.debrisContainer)
	task.spawn(function()
		Hitbox.Shape = Shape
		Hitbox.Size = Size
		Hitbox.CFrame = Cframe
		Hitbox.Transparency = 1
		Hitbox.CanCollide = false
		Hitbox.CanQuery = false
		Hitbox.CanTouch = false
		Hitbox.CastShadow = false
		Hitbox.Anchored = true
		Hitbox.Name = ("Hitbox%s"):format(tostring(math.random(1, 999999999999999)))
		table.insert(Hitboxes, Hitbox)
	end)
	local HitboxActual = VoxelDestruction.hitbox(Hitbox, 0, false, false, 1, Params, MinimumVoxelSize, nil, nil, nil, TimeToReset, nil, nil, nil)
	local Touched = Signal.new()
	HitboxActual.Collision:Connect(function(debris, walls)
		Touched:Fire(walls)
	end)
	HitboxActual.WeldTo = function(part)
		task.spawn(function()
			if RunService:IsClient() then
				local connection = RunService.RenderStepped:Connect(function()
					if part then
						Hitbox.CFrame = part.CFrame
					end
				end)
				local connection2 
			else
				local canRun = true
				local connection
				while canRun do
					if part then
						Hitbox.CFrame = part.CFrame
					end
					task.wait()
				end
			end
		end)
	end
end

return VoxBreakerAPI

Still works though
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

1 Like

Isn’t VoxBreaker having a major update too?

yeahhhh but I just made an api to fastly migrate from breaker to this since this module is actually more perfomant

Do you know how to make voxels exactly the size you want (1.5, 1.5, 1.5)? They become bigger or smaller relative to the wall.

ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅
it splits these into really tiny and thin parts, omg it also lags so much on tiny objects


like this, its so bad actually (yep its worse than voxbreaker in optimization)
like what is this:
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

bro like what is this???
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

There’s an issue with an update I pushed, I’m working on fixing this.

1 Like

waiting for fix my sweetie, I really like your module and looking forward to do some contributions

but you updated it 2 months ago
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

1 Like

Fixed the no meshing bug!
Sorry.

1 Like

Did you update the model?
or whar Edit: now module doesnt return anything
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅
Edit 2: nevermind i forgor to change attribute
Edit:3


Edit:4
Why does this happen with gridlock on?
ΠΈΠ·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅

1 Like

Why the hell it counts big floor as a debris???


Ok what the hell:

1 Like

As long as parts are anchored and the attribute is set correctly then there should be no odd occurrences. If the floor is being broken then that means its either parented to an instance which has the attribute or it has the attribute itself.

Turn gridlock off if you don’t want very thin pieces, its an unexpected result from floating point decimals, kind of a tricky thing to fix. Gridlock was intended for neatness so its not a necessary feature to use anyway and I may just remove it.

I updated the model with a bug fix that should bring any lag down so try it if you haven’t already.

1 Like

no each part is separated and is not parented to other parts so i dont know whar are you talkin about

1 Like

Hey real question here about the module,

So I’ve been trying to use the .hitbox() function and after doing extensive research it’s still giving me a lot of trouble (maybe I missed crucial info? I’ve been at this the entire night and I can’t get it working)

Essentially the problem is that whenever I use the .hitbox() function on an already existing object (in this case, module) and I move it with the tools provided by studio, it works perfectly fine


image

Code sample and the structure of the object^

When I load the game in Run mode, or Play mode, whichever,
and I drag it with the tools given by the studio, it works perfectly fine and breaks any surface it comes in contact with

The problem arises when I try to do the same but from an already existing script, which happens to be a module (used for the combat system of my game)

By executing the exact same identical code, after cloning the object, it seems to not be capable of breaking anything, and doesn’t detect any collisions;

Possibly important facts:
The projectile within the module script uses body velocity to move
I’ve given the already existing target object body velocity, and it seemed to work just fine with it, as long as it is not made by the module script

Duplicating the server script while it is inside the object, and enabling it after it’s created within the module doesn’t work either, only seems to work if the Object wasn’t created by the module script

Cloning, duplicating, anchoring, unanchoring the object doesn’t seem to affect it at all as long as it hasn’t been created by the module script

Using the module script for the creation of the object is crucial.

Here’s a gif demonstrating the difference in activity;

RobloxStudioBeta_NmoOHrAYmZ

It might be hard to see after snapping to the player perspective, but the projectile does not break the wall or interact with it in any way at all despite being 1:1 identical to the one used at the beginning of the demonstration gif

Why?

edit,

After multiple tests and grasping at straws I found out that the .hitbox() function only and ONLY performs while I am in SERVER view inside STUDIO

what

final edit and solution for people who are potentially struggling with this

the problem was that the .hitbox() function utilized BindToRenderStep which only functions on a client script, since the server can’t use .RenderStepped() as it requires to detect the rendering frames

RobloxStudioBeta_0QVXc8RyhC

line ~893 in main module^

this explains why it only worked in studio’s server view as the server got an active observer (renderer) when you switched to it, allowing BindToRenderStep to work

my solution was to rebind it to HeartBeat which the server is cool with, although I can’t vouch for how good of an alternative that is

1 Like