VoxBreaker | An OOP Voxel Destruction module

OHHH I DIDNT SEE THAT Sorry, i am stupid and eepy
Edit:
Actually tags are more perfomant than attributes, i prefer to use them.
Edit 2:
Couldnt find any bugs, but new version is much more perfomant and better in voxelizing stuff, gonna implement some code from it into my api that i may release soon (it adds sounds, particles, neon screens breaking, etc…)
Edit 3:
theres one major bug, its deleting the walls and when
изображение
this setting set to false almost no debris appear, likely because its deleting all parts that are under size or over size of the minimum voxel size, i would like to see this setting work like in jujutsu shenanigans(because its making parts cubic and then resizes them somehow, couldnt figure it out, but if i find solution will make post about this!) or something like the gridlock in voxel destruct.
изображение


as you can see its just deleting everything.

1 Like

I still appreciate your work very much! looking forward to see the completed version of this module rework.

1 Like

We appreciate all of your hard work! I’m really happy about the move to tags. The module still needs some clean up, but this is something I’ll contribute on the repository once this version is released.

1 Like

An issue I came across were subdivided parts not disappearing when further destructed upon. I managed to find a fix by adding the following lines of code into the :ConstructVoxels() method (under the for loop):

if partInfo.OriginalPart then
	partInfo.OriginalPart:RemoveTag('Voxel')
end

Edit: Also thank you very much for making this module! I really appreciate what you’ve given us to use for our own works.

1 Like

The Raycast keep detecting the hitbox and exclude doesn’t work, how to fix this?

Hows it going with the module?

do you have any idea how i could fix making player get flung or something when using the createhitbox on a floor? so far it hasnt been going great and its really annoying… this is the script i used

local PhysicsService = game:GetService("PhysicsService")

local collisions = "Voxel"

-- Function to set up collision groups
local function setupCollisionGroups()
	-- Create the collision group if it doesn't exist
	if not pcall(function() PhysicsService:CreateCollisionGroup(collisions) end) then
		print("Collision group already exists.")
	end
	PhysicsService:CollisionGroupSetCollidable(collisions, collisions, false)
end

local function setCollisionGroup(parts)
	for _, part in ipairs(parts:GetDescendants()) do
		if part:IsA("BasePart") then
			PhysicsService:SetPartCollisionGroup(part, collisions)
		end
	end
end

-- Call setup function at the start of the script
setupCollisionGroups()

local function handlevoxelbreaker(CF)

	local TweenService = game:GetService("TweenService")
	local deb = game:GetService("Debris")







	local VoxBreaker = require(game.ReplicatedStorage.VoxBreaker)
	local Size = Vector3.new(10, 10, 10)

	-- Set the Cframe to be in front of the HumanoidRootPart
	local Cframe = CF
	local Shape = Enum.PartType.Ball
	local MinimumSize = math.random(2.5, 4)
	local Seconds = 5

	-- Assign player parts to PlayerGroup collision group
	task.spawn(function()
		local Voxels = VoxBreaker:CreateHitbox(Size, Cframe, Shape, MinimumSize, Seconds)
	local playedSounds = {}

		for _, v in pairs(Voxels) do
			setCollisionGroup(v)
		if math.random(1, 2) == 1 then
			v.CastShadow = false
			v.Anchored = false
			v.Massless = true
			v.Size = v.Size - Vector3.new(0.05, 0.05, 0.05)

			-- Set voxel to VoxelGroup collision group
			PhysicsService:SetPartCollisionGroup(v, "VoxelGroup")

			local initialVelocity = v.Velocity.Magnitude
			local soundsFolder = game.ReplicatedStorage.Rockimpacts
			local soundNames = {}

			for _, sound in pairs(soundsFolder:GetChildren()) do
				if sound:IsA("Sound") then
					table.insert(soundNames, sound.Name)
				end
			end

			local function playImpactSound()
				local currentVelocity = v.Velocity.Magnitude
				if not playedSounds[v] or math.abs(currentVelocity - initialVelocity) > 5 then
					playedSounds[v] = true
					initialVelocity = currentVelocity
					if math.random(1, 3) == 1 then
						local particle = game.ReplicatedStorage.Rockimpactpar["skin" .. math.random(0, 2)]:Clone()
						particle.Parent = v
						particle.Enabled = true
						deb:AddItem(particle, 0.5)
					end
					if #soundNames > 0 then
						local randomSoundName = soundNames[math.random(1, #soundNames)]
						local randomSound = soundsFolder[randomSoundName]:Clone()
						randomSound.Parent = v
						randomSound:Play()
						game:GetService("Debris"):AddItem(randomSound, randomSound.TimeLength)
					else
						warn("No sounds found in ReplicatedStorage.Rockimpacts.")
					end
				end
			end

			local touchedsounddeb = false
			v.Touched:Connect(function()
				local touchingParts = v:GetTouchingParts()
				if #touchingParts > 0 and not touchedsounddeb then
					touchedsounddeb = true
					playImpactSound()
					task.spawn(function()
						wait(0.5)
						touchedsounddeb = false
					end)
				end
			end)

			-- Despawn the voxel by tweening its size to 0
			local tweenInfo = TweenInfo.new(Seconds, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
			local goal = { Size = Vector3.new(0, 0, 0) }
			local tween = TweenService:Create(v, tweenInfo, goal)
			task.spawn(function()
				task.wait(1)
				tween:Play()
			end)
		elseif math.random(1,2) == 2 then
			v:Destroy()
		end

	end
	end)
	
end