Hi! I am wanting to make a destruction game where you destroy parts with explosions, but I want a bunch of smaller parts that make up the map. To do this I want to fill a part,
This is a fairly hard geometry problem and you can significantly limit how hard it is by limiting what cases you want to model. Do you just want to be able to run this in studio or have it work in real time when the part takes damage?
When a part takes damage, how do you want it to be divided? The easiest case would be to divide a block into two, four, or eight parts along its center. The harder way is to divide it unevenly around the point where damage is taken / point of impact. The hardest way would be to divide it enough times to allow a “crater” to be cut out of it. These build off of each other, so I would advise you do the easy one first and then decide if its good enough. Do you feel comfortable doing the first one, in terms of your math and scripting ability?
local bipolarVectorSet = {
Vector3.new(1,1,1),
Vector3.new(1,1,-1),
Vector3.new(1,-1,1),
Vector3.new(1,-1,-1),
Vector3.new(-1,1,1),
Vector3.new(-1,1,-1),
Vector3.new(-1,-1,1),
Vector3.new(-1,-1,-1),
}
local function DivideBlock(block : Instance)
local halfSize = block.Size / 2.0
for _, offsetVector in pairs(bipolarVectorSet) do
local clone = block:Clone()
clone.Parent = workspace
clone.Size = halfSize
clone.CFrame += block.CFrame:VectorToWorldSpace((halfSize / 2.0) * offsetVector)
end
block:Destroy()
end
Just call DivideBlock() and pass the block you want to cut.
There isnt a good way to cut a sphere or cylinder exactly, except for the special case of cutting a cylinder into discs. My workaround would be to break those into blocks that closely approximate the shape, similar to how you’d make a sphere or cylinder in minecraft.