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
1 Like

Is it just me or does the test place cause an immense lag spike when spawning the voxels? Does the module consistently cause lag spikes like this?

I have not looked at how it’s scripted, but perhaps it’s because it’s spawning too many parts in one frame. It may be better to spread it out over a couple frames, but I don’t know, just speculating based on my couple minutes of testing it.

Mine did that too, until I turned on StreamingEnabled (I have no idea why it affects it)

Bartokens has abandoned us :pray: :sob:

2 Likes

I’ve just taken a break from roblox development lol. I’ll get back to updating in a week or two

2 Likes

Same got to play minecraft after 2 years… Lol

2 Likes

Anyone else getting an issue where the debris kinda glitch and then the whole part disappears? Only error i get is Attempts to index nil with parent in the module other than that works amazing.

1 Like

yea I got that and till this day I have no idea how to fix it

Barto, it’s been 2 weeks bbg. :stuck_out_tongue:

I NEED that voxbreaker update :sob: :pray:

ON GOD :stuck_out_tongue: bro bro better push it out NOW or else im gonna…

Get freaky

Same the whole baseplate was gone :cry:

A bit late on this, but to make the parts cubic, youd have to subdivide either by 3 or 2 and use an algorithm to decide for that, which is rounding the remainder (using modulo) and deciding whether subdividing by 3 or 2 will get you closer to the goal of 2x2 or whatever part size you want. This wont give you the perfect size but gets you very close to a perfect cube divide. I believe JJS and realm rampage both use that little empty space as a means to get rid of the remaining amount after subdividing into cubes. This would probably only work well in a less detailed map though.

same issue here, like the floor is getting unanchored or something :person_shrugging: