VoxBreaker | An OOP Voxel Destruction module

No worries, we appreciate you for updating the module and trying to create a repository! If you’d like, I can explain to you how GitHub works and help you set up a repository for the project. :grinning:

1 Like

That would be helpful. Shoot me a dm, if youd like to assist I would appreciate it. And you dont have to fully explain it to me if its inconvenient for you, you could just direct me to some learning resources on github.

Hello, how would I do this using weld to?

Its basically the same thing. With moveable hitboxes you just fire the parts to the client for every time the hitbox is touched using the .Touched Event

1 Like

Do you think CSG will be better than how voxel modules operate currently? and would you ever implement it in this resource?

EX:

While CSG operations are currently functional but not super performant, I’m sure they will improve vastly in the future. And I think that’s awesome, I would love to make a game with Metal Gear rising cutting mechanics, and I can’t wait to see what people do with them.

That being said, it is a bit of a hard comparison. Voxel destruction as you may already know, is not intended to serve as some sort of realistic destruction. While you may use CSG operations for things like bullet holes or swords slashing through walls, they serve an entirely different purpose and aesthetic.

My intention with VoxBreaker was to mimic voxel destruction found in games such as Teardown, Voxel Destruction Physics, and Jujutsu Shenanigans. And those games do not follow a realistic approach, and neither does VoxBreaker. Voxel destruction is not intended to be realistic destruction, and looks entirely different than what you can do with the CSG operations. So I can’t really say if CSG will be better than VoxBreaker. Performance-wise, maybe, but they look and act entirely different, and in some use cases, serve entirely different purposes.

And I likely won’t implement CSG into VoxBreaker. The only instance where I would, is if CSG operations provided some greedy-meshing like operation where I could merge parts without lag.

Is there a way to completely prevent the voxels being smaller than the minimum size? Have some voxels alot smaller than others is pretty annoying.

hello, I did what you said, it seems to work but there is a problem. The debris are positioned differently on each client

Code:

-- Server Script

local module = {}

function module.StartMovable(params)
	
	local Size = params['Size']
	local Cframe = params['Cframe']
	local Shape = params['Shape']
	local part = params['part']
	local Timer = params['Timer']
	local KB = params['KB']
	local DIR = params['DIR']
	local Destroy = params['Destroy']

	

	local VoxBreaker = require(game.ReplicatedStorage.Scripts.Modules.VoxBreaker)

	local PART = Instance.new('Part', part)
	PART.CanCollide = false
	PART.Massless = true
	PART.Transparency = 1


	local w = Instance.new('Weld', PART)
	w.Part0 = part
	w.Part1 = PART
	w.C0 = Cframe

	local Voxels = VoxBreaker.CreateMoveableHitbox(4, 20,Size,Cframe,Shape)
	Voxels:Start()
	Voxels:WeldTo(PART)



	
	
	coroutine.wrap(function()
		local connection
		connection = Voxels.Touched:Connect(function(Parts)
				
				for i,v in pairs(Parts) do
					if Destroy then
						v:Destroy()
					else
					game.ReplicatedStorage.Events.VoxClient:FireAllClients(params, v)
					task.wait()
					v:Destroy()
					end
				end
			
		end)
	end)()
	
	
	delay(Timer, function()
		Voxels:Destroy()
		PART:Destroy()

	end)
end

return module

-- Local Script

game.ReplicatedStorage.Events.VoxClient.OnClientEvent:Connect(function(params, targ)
	
	if not targ then return end
	
	local part = params['part']
	local KB = params['KB']
	local DIR = params['DIR']

	local Clone = targ:Clone()
	Clone.Parent = workspace
	Clone.Anchored = false
	
	Clone.Size = Vector3.new(Clone.Size.X -0.1, Clone.Size.Y -0.1, Clone.Size.Z -0.1)

	delay(10, function()
		local tweenService = game:GetService("TweenService")
		local tweenInfo = TweenInfo.new(
			1, --Time
			Enum.EasingStyle.Linear, --EasingStyle
			Enum.EasingDirection.In, --EasingDirection
			0, --Repeat count
			false, --Reverses if true
			0 --Delay time
		)
		local tween = tweenService:Create(Clone, tweenInfo, {Transparency = 1})
		tween:Play()
		game.Debris:AddItem(Clone, 1)
	end)

	if KB and not DIR then
		task.wait()
		local NODIRBV = Instance.new("BodyVelocity")
		NODIRBV.MaxForce = Vector3.new(1000000,1000000,1000000)
		NODIRBV.Velocity = KB
		NODIRBV.Parent = Clone

		delay(0.3, function()

			for IN, VAL in pairs(Clone:GetDescendants()) do
				VAL:Destroy()

			end
		end)


	else
		task.wait()
		local dir = CFrame.new(part.CFrame.p, Clone.CFrame.p).LookVector
		local DIRBV = Instance.new("BodyVelocity")
		DIRBV.MaxForce = Vector3.new(1000000,1000000,1000000)
		DIRBV.Velocity = dir * KB
		DIRBV.Parent = Clone

		delay(0.3, function()

			for IN, VAL in pairs(Clone:GetDescendants()) do
				VAL:Destroy()

			end
		end)
	end


	
end)

Yes, that is inevitable. If you want the voxels to be posititoned the same then i believe the only way is to use the module on the server.

1 Like

I have a question, how would parts made from local scripts be interactable on the vox module when fired through the serverscript?? like have the vox hitbox that was fired from a server be able to detect a debris created from a local script in order to fiddle, fling, toss or destroy

image
i dont know why it keeps breaking it into these small parts when i set the minimum voxel size to 5

Is their a way where you can set all the parts back to where it originally was, but in a smooth way? Incorporating tween service for the building system would be nice instead of just making it reform like normal.

So in other words, you want the parts to return to where they were by moving them, rather than just teleporting them back into place and resetting the voxels?

1 Like

I have been playing with this module for about an hour, and i’ve noticed a bug i think,
whenever i go under the minimum size of 5, it ignores the minimum setting.
i think it’s cause i’m sometimes trying to make it do weird voxelizations but i thought it’d just do the whole part rather then forcing it to make a square.

image_2024-06-02_214357847

is there maybe something i’m doing wrong?
while i dont mind it being a 5 size block, i still wanted to try out smaller sizes.

1 Like

correct, reforming the structure in a smooth way.

I want to hear more about the game you’re working on. Is it based on an anime(s)? Is it a battlegrounds or arena type? Spill the details!

1 Like

Basically a battlegrounds game with some unique mechanics, loosely inspired by elemental battlegrounds. And ill be implementing voxbreaker into it as well. Ive already shared some details on my socials, so you can check my discord or tiktok if you’d like. You can find links in the group on my bio.

So this isnt that hard of an effect to do, you wont even need to change the code of the module. Its as simple as tweening the part back into its original position before the reset time. Or you could lerp, or use bezier curves if youd like. You just have to store the original vector 3 position of each part and have some way of calling on it. The easiest way would be attributes, but you could use tables, or possibly tags.

But there is a bit of a catch that might break some things: when you call a hitbox on a part that has already been voxelized, then the reset time of that part will be overwritten with the reset time of the new hitbox. Im considering changing how this works in the future, but for now if you try this you might notice some inconsistencies or strange behavior.

Yes thats exactly what I did; I’m just saying it’d be nice if you implemented it to your module as some other users do not know how. and yeah their is a strange behaviour; after the reset time is done, the voxelised part goes black and back to normal within a split second, its kinda annoying.

1 Like

That sounds awesome, I’ll check it out once you release it,

If you can think of any tools/modules you’d need now or in the future please let me know, I’m trying to make a portfolio of community resources so it would be beneficial for me to help in any way possible.

Good luck on your project!

2 Likes