TLDR: Base parts are converted into voxels which is laggy HELP!
-
What do you want to achieve? Keep it simple and clear!
I’m trying to make a voxel destruction system for fun, but I’m running into massive lag issues. Basically I want to seamlessly convert a base part into smaller voxels, with automated welding to allow pieces to fall as expected. I want it to be something like teardown, but I’m struggling to get there. -
What is the issue? Include screenshots / videos if possible!
I’m trying to automate the welding by of voxels by using GetTouchingParts() but this results in more parts being listed than expected(it’s getting diagonal voxels as well), and double welds, which is very inefficient.
(I am using spawn function as the game will freeze up completely otherwise), this script is also run on every voxel that spawns which I’m sure isn’t efficient.
spawn( function()
voxel.Size = voxel.Size + Vector3.new(0.001, 0.001, 0.001)
for _,v in ipairs(voxel:GetTouchingParts()) do
if v ~= part and v.CollisionGroup == "Destructible" then
local weld = Instance.new("WeldConstraint")
weld.Parent = voxel
weld.Part0 = voxel
weld.Part1 = v
weld.Enabled = true
end
end
voxel.Size = voxel.Size - Vector3.new(0.001, 0.001, 0.001)
voxel.Anchored = false
end)
(None of the tools were made by me and are free assets)
Weirdly enough if I use this wrecking ball then there’s no lag when welding, and I can’t figure out why…
I’m also wondering if there’s a better way of creating the voxels, right now I am just splitting the part into 8 voxels with a recursive function/loop(they will voxelize further depending on the distance from the hit position) as shown by the image below:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Part of my problem may be due to the whole script being serverside, but I imagine this wouldn’t speed up the welding if it were on the client.
I’ve tried looking everywhere, but a lot I can’t find a good way to weld adjacent parts(The only two solutions I’ve seen is GetTouchingParts and Region3), I’ve also looked for better ways to create voxels, but a lot of the roblox related stuff is more laggy/clunky than my current setup. I’ve also tried searching for solutions in other languages and porting them over to roblox, I’ve also seen stuff where they render the voxels as one mesh(which I am way to stupid to understand). Whilst searching for a solution I found this video, which means that it’s definitely possible… maybe I’m just not smart enough.
Voxel destruction tech - YouTube