Laggy Voxel Destruction system

TLDR: Base parts are converted into voxels which is laggy HELP!

  1. 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.
  2. 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:
Voxel Configuration

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

Ok, I rewrote the whole thing, and I have a pretty instant, and reliable voxel destruction system, I changed my scripts so that large parts would be split into 64 pieces, and smaller parts would be split into 1,1,1 sized cubes, I also used this: Greedy Meshing Algorithm - Roblox Scripting Tutorial - YouTube greedy meshing tutorial, which I adapted to my needs, I also made the parts not combine if they were close to where the destruction was happening, this also helped with decreasing the amount of welding needed, I’m not sure exactly why my last welding method was so laggy… Now all I need to do is unanchor parts that haven’t been voxelized…

Edit: I have found an even better way to weld stuff via this post: Horrible performance when using welds instead of :MakeJoints() within models?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.