Recommended way to randomly generate holes in Baseplate

  1. What do you want to achieve? I have a script which randomly generates underground bunkers in an infinitely generated floor made of baseplates and uses SubtractAsync to make holes so they fit

  2. What is the issue? None of the CollisionFidelities seem to fit my use case

  3. What solutions have you tried so far?

  • Default CollisionFidelity => can’t enter hole
  • Hull CollisionFidelity => can’t enter hole
  • Box CollisionFidelity => can’t enter hole
  • PreciseConvexDecomposition CollisionFidelity => works most of the time, but sometimes decides to make the entire baseplate collision the depth of the bunker’s floor, leading to players getting softlocked inside of the baseplate

I have thought of using some formulas to split it into parts instead, because the things I have to subtract are all blocks parallel to X,Y,Z, but is that really the right way to do it in a game engine which has built-in mesh subtraction

What would the best solution to this problem be?

1 Like

can i see the code by any chance

1 Like
local bunk = workspace.Bunker
bunk.Parent = nil

local r = Random.new(os.time())

_G.generatescripts = {
	[...],
	function(s, e)
		for i=s+1,e do
			if math.random(1,500)==1 then
				local b = bunk:Clone()
				b.Parent = workspace.generated
				local rotation = CFrame.Angles(0, math.rad(r.NextNumber(r,0,360)), 0)
				local pos = CFrame.new(Vector3.new(i,0,math.random(-4096,4096)))
				b:PivotTo(pos * rotation)
				for _,i in workspace:GetPartsInPart(b.RemoveFromTerrain) do
					local pd = i
					local good = true
					while pd ~= workspace do
						if pd.Name == "Bunker" then
							good = false
						end
						pd = pd.Parent
					end
					if good then
						pcall(function()
							local fi = i:SubtractAsync({b.RemoveFromTerrain}, Enum.CollisionFidelity.PreciseConvexDecomposition) -- Even with this, the collision sometimes decides to be inaccurate as described in the post
							fi.Parent = i.Parent
							i:Destroy()
						end)
					end
				end
			end
		end
	end,
	[...],
}
[...]
1 Like

Fwiw it might be best to just bite the bullet and dynamically cut holes in the floor using parts. Sure Roblox has in-game mesh subtraction but unions aren’t very well optimized (ie unions have a big issue with redundant geometry), and they can fail unpredictably. Plus the operation takes an indefinite amount of time and when the operation is performed in game, can have issues like flickering depending on the complexity of the operation. You also can’t separate unions in game (so if you’re wanting to remove a bunker you’d have to use a hacky workaround like either saving the previous unions, or reconstructing the ground from scratch), among a plethora of other issues/lacking features.

I don’t want to discredit the team who’s working on them – it’s great that there’s work being done on it, but in my opinion I don’t think in-game CSG operations are feasible for production yet.

Cutting the parts out yourself negates all of the aforementioned issues, plus you get fine grain control over the geometry, 100% accurate collisions (which was a big issue in your case), etc.

If you need any help with an implementation, let me know.

1 Like

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