Accurately reading terrain voxels then destroying

hey this is my first forum post, kinda new to this thing. i tried looking on the forums but i did not discover the exact issue im encountering

  1. What do you want to achieve? Keep it simple and clear!
    better depiction of voxels. i find it hard to accurately read voxels with parts converted to region 3’s, while it works its not 100%.

i am creating a digging system that involves voxel destruction and im looking to get to feel not jank. i feel like this might be a limitation with the resolution being locked to 4 studs but im not sure so im posting here

  1. What is the issue? Include screenshots / videos if possible!
    i am reading the voxels and then using fillregion() to get an accurate display on how many voxels has been destroyed and what type but it feels extremely jank and has issues

https://gyazo.com/5e70d2371c40e68d84403702c0342cc6.mp4
https://gyazo.com/5fe4aa6299a9c66acba3b7478bb576f4.mp4
https://gyazo.com/844afd1ba690502659e90f29995500ab

while it works SOME times it isnt very satisfying lol

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i have tried a few other solutions, the only one that seemed to work was using fillblock() while that worked perfectly for destroying voxels, it was difficult to get it to accurately give a reading on what voxels have been destroyed and or modified. (either not even detecting them gone or detecting too many / duplicates)

i have also tried looking across the dev forums, and googling it/ searching through reddit but i cannot find anything with the exact issues as me

i appologise for the whitespace lol

  ----------------------------------------------------------------------------------------------------------------------------------------------
	


	local size = digger.Size
	local region =  Region3.new(digger.Position - size/2, digger.Position + size/2)
	--terrain:FillRegion(region,4,Enum.Material.Air)

	local voxelData = terrain:ReadVoxels(region, 4)



	local function voxelFunc(voxel)
		if not canDig then
			return
		end

	    local highestMaterial = nil
	    local highestCount = 0
	    voxelDetected = voxelDetected + 1

	    if _voxelDestroyed >= MaxCapacity then
	        return
	    end

	    if voxelMaterial[voxel.Name] then
	        voxelMaterial[voxel.Name] = voxelMaterial[voxel.Name] + 1
	    else
	        voxelMaterial[voxel.Name] = 1
	    end

	    for material, count in pairs(voxelMaterial) do
	        if count > highestCount then
	            highestCount = count
	            highestMaterial = material
	        end
	    end

	    materialDisplay = highestMaterial
	   

	    _voxelDestroyed = math.min(_voxelDestroyed + voxelDetected, MaxCapacity)
		print(_voxelDestroyed)
	    terrain:FillRegion(region, 4, Enum.Material.Air)

	    destructionPercentage = _voxelDestroyed / MaxCapacity
	    --voxeltoVisual(destructionPercentage)
	end
----------------------------------------------------------------------------------------------------------------------------------------------
	
	

	--get voxel information
	for x = 1, #voxelData do
    	for y = 1, #voxelData[x] do
    	    for z = 1, #voxelData[x][y] do
       	     local voxel = voxelData[x][y][z]
				if voxel.Name == "Air" then
					return
				end
			
			
			voxelFunc(voxel)		
			end
		end
	end

i have thought of a solution, i realise that this code may possibly only be checking if that voxel is fully occupied and or full and it isnt checking partially and thats why it only works when its perfectly aligned and looks jank. ill keep updated on if this works or not incase anyone else is having the same issues as me and wants some form of documentation!

okay update, for anyone using a similar solution for tracking and deleting voxels with regions, check for occupancies and specifically i believe what was wrong with my code personally was this line here

if voxel.Name == “Air” then
return
end

i think the return on this function when it detects the first air voxel is the specific reason why it had issues. (its leaving when it detects the first air voxel in that region and is ignoring the rest) im not exactly sure if checking the occupancy even helps but i think that was my main issue

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