Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Best way to fragment a part/model into multiple parts?

Asked by 5 years ago

My game is designed to blow stuff up, that being said; I've made a big house and the walls in it are solid and close to impossible to knock down with explosives. I cannot seem to find the right math to make an 8x8 block into multiple 2x2 blocks in the same position/color/property.

1 answer

Log in to vote
1
Answered by
fredfishy 833 Moderation Voter
5 years ago
Edited 5 years ago

If you're trying to split up a cube, then the following should work.

function splitCube(block, divisions)
    for x = (-divisions/2+0.5), (divisions/2) do
        for y = (-divisions/2+0.5), (divisions/2) do
            for z = (-divisions/2+0.5), (divisions/2) do
                local p = block:Clone()
                p.Parent = block.Parent
                p.Size = block.Size / divisions
                p.CFrame = block.CFrame + (Vector3.new(x, y, z) * (p.Size.x))
            end
        end
    end

    block:Destroy()
end

The +0.5 is down to the way position is in the centre of a part, not the edge.

Alternatively, you could increase the BlastPressure of whatever explosions you're using.

1
Works perfectly, you're a godsend. I won't forget this, thank you. LucarioZombie 291 — 5y
Ad

Answer this question