VoxBreaker | An OOP Voxel Destruction module

This is probably being caused by this segment of code:

image

You can delete that and it should work like normal. I only put that on there to try and see if it would fix the bug I mentioned before, but it obviously didn’t so I would just delete it for now. I’ll remove it in the next update.

2 Likes

I did try this, but I did find an issue where large chunks of parts would get cut out for some reason. Though this only happens when partcache is enabled.


Also, I still see a bit of a flash when I use this method, not sure how it looks for you though.

1 Like

Oh I havent used the part cache version of this module since I am doing alot of client sided things with the voxels and destroying them.

1 Like

I dont mean to be rude but ever since you implemented PartCache, this module has been getting a bit worse. Hopefully the new algorithm will solve these issues but for now here is my modified version of this module. Ive re-formatted it and it works like a breeze. Just make sure to send over the voxels to the client and its pretty much seamless and does not use PartCache.

VoxBreakerCustom.lua (38.4 KB)

Here is how I handle the voxels on the client:


Its in TypeScript but im sure anyone can understand the ideas here.

1 Like

I’ll agree with you there to some degree. The inclusion of PartCache did sort’ve complicate the module, and my code got a little bit messy. But that’s the reason why I left PartCache on as an option that can be toggled in the module settings, as you may come across issues with replication due to how PartCache works. But overall it does help with performance to some extent. But hopefully the new algorithm I’m introducing will alleviate the need for PartCache to some extent. Other than that, the only big optimization changes I could make are swapping attributes to tags, and adding greedy meshing. (those may or may not be coming in the next update.)

should i be cloning voxels to the client or just using the module on the client because i kind of want to make it so i can interact with voxels more than once but idk how id do that with cloning them to the client

when wanting to interact a voxel debris when cloned i recommend liek putting it in a table to store the amount of voxels in the client and have the server fire a event which makes the cloned voxels detect if they are inside a hitbox in order to interact client cloned voxels

1 Like

Absolutely love this module. Like CompletedLoop said, PartCache is a little wonky, but besides that flaw, this module has been an absolute lifesaver for me! So glad I didn’t have to make my own module to do destruction physics :sweat_smile:

2 Likes

How would i implement layers for how my voxels will react for example having a inner layer which if a voxelpart hits it gets destroyed and having a outer layer make debris out of voxel parts??

Excuse me, for some reason when i use the module to break some parts with a hitbox, it always seems to freeze/lag, why is that? (Multiple people tested)

Hi barto, for some reason random parts just refuse to respawn, i cant see any sort of condition that triggers this it seems to just be at random

As the original creator of Vex, I definitely agree. Even though I had planned to revitalize it at some point, it always got away from me and with time I had to let go of that idea. VoxBreaker is something I would for sure endorse and promote to anyone needing simple, performant voxel destruction capabilities.

Maybe I’ll peek around in VoxBreaker sometime soon, never know what I’ll recognize or be able to improve upon. Haha. :rofl: :+1:

(also side note. sorry about anyone (including you unfortunately) who i ghosted accidentally who either asked me about Vex or wanted an update. i no longer use eternalethel as my main account and i don’t use devforum as much i used to)

1 Like

Could you send a video demonstrating this?

Well this could be happening for a number of reasons. If you could send me your code or any videos showing this that would help.

Don’t worry about it, this project was definitely a learning process and I’m glad I went through with it. And your module did help me to some extent.

2 Likes

Okay, here it is, it made my studio crash 4 times

As you can see, the first one lags a bit, the second time crashed studio

I would send a script but idk how to format it

Yeah from what I’m seeing it’s very likely that it’s either how you built your map or something in your code.

–Server Script
local VoxBreaker = require(game.ReplicatedStorage.VoxBreaker)
local remote = game.ReplicatedStorage.RemoteEvent

remote.OnServerEvent:Connect(function(player,cframe)
local voxels = VoxBreaker:CreateHitbox(Vector3.new(5, 6, 6),cframe,Enum.PartType.Ball,1,20)
for _,voxel in voxels do
voxel.Parent = game.ReplicatedStorage --Parent voxels to replicated storage so that the client can see them
end
remote:FireAllClients(voxels,cframe) --Fire the table back to the client before destroying them on the server
for _,voxel in voxels do
voxel:Destroy()
end
end)

for _, part in workspace.Map[“Biome Sprites”]:GetDescendants() do
if (part:IsA(“BasePart”) or part:IsA(“MeshPart”) or part:IsA(“UnionOperation”)) and (part.Name ~= “Snowflakes”) then
part:SetAttribute(“Destroyable”, true)
end
end

for _, part in workspace.Map.Biomes:GetDescendants() do
if (part:IsA(“BasePart”) or part:IsA(“MeshPart”) or part:IsA(“UnionOperation”)) and (part.Name ~= “Snowflakes”) then
part:SetAttribute(“Destroyable”, true)
end
end

–Local Script
local crumbleSound = script:WaitForChild(“crumble”)

local VoxBreaker = require(game.ReplicatedStorage.VoxBreaker)

local Random = Random.new()

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(voxels,cframe)
local sound = crumbleSound:Clone()
sound.Parent = voxels[1]
sound.PlaybackSpeed = Random:NextInteger(0.85,1.15)
sound.Volume = sound.Volume
sound:Play()
game.Debris:AddItem(sound, 3)
for _,voxel in voxels do
local clone = voxel:Clone()
clone.Parent = workspace.Destruction
clone.Anchored = false
local velocity = CFrame.lookAt(clone.Position,cframe.Position).LookVector * (-85 * (clone.Mass))
clone:ApplyImpulse(velocity)
clone.Velocity = velocity / 8
clone:ApplyAngularImpulse(velocity)
clone:SetAttribute(“Destroyable”, true)
end
task.wait(30)
for _,v in workspace.Destruction:GetChildren() do
v:Destroy()
end
end)

Sorry I’m new to the devforum and don’t know how to format

I dont believe this script should make it lag though

I’m noticing a few issues here. For one you shouldn’t be setting BaseParts or unions to destroyable. The module only divides normal parts.

Your also setting your minimum voxel size to 1. I don’t really recommend setting that so low as it will result in a ton of parts and could kill performance.

In addition, your also using apply impulse twice in a row. Not sure if that’s the issue here but it’s a possibility.

And if none of that fixes your issues, then you could have children nested under your parts. If you have any scripts within your destroyable parts, then they could be getting cloned and adding onto the lag.