How can I break a part into X amount of small pieces?

SmallPart.Position = Part.Position

i forgot to do that

Thats going to put every part in the middle. I’m trying to make them all fill the pane of glass pretty much.

But you would have to use negate and union, And it will affect the games performance

1 Like

You dont have to union it. You can create parts and position them.

Made this but I haven’t tried it. Let me know if you have any errors:

local function createPieces(part) -------- part is the window
    if part ~= nil then
        local size = part.Size
        local position = part.Position
        local pieces = (size.X+size.Y)/2
        for i = 1, pieces do
            local piece = Instance.new("Part", workspace)
            piece.Name = part.Name.." piece"
            piece.Size = Vector3.new(size.X/pieces, size.Y/pieces, size.Z)
            piece.Position = Vector3.new(math.random(-posiion.X/1.25, position.X/1.25), math.random(-position.Y/1.25,position.Y/1.25), position.Z)
            piece.Color = part.Color
            piece.Transparency = part.Transparency
            piece:ApplyImpulse(part.CFrame.LookVector * 50) ---- delete if you dont want the pieces to fling slightly
        end
        part:Destroy()
    end
end

createPieces()
1 Like

https://gyazo.com/6a0fbde0d9796a2249c7c9d99c1ff370

Here is the result.
I would also sometimes get this error if I hit one of the panes of glass that was angled differently.

invalid argument #2 to 'random' (interval is empty) 

Fixed it. Put this in the part you want to break:

local function createPieces(part) -------- part is the window

    if part ~= nil then

        local size = part.Size

        local position = part.Position

        local pieces = (size.X+size.Y)/2

        for i = 1, pieces do

            local piece = Instance.new("Part", workspace)

            piece.Name = part.Name.." piece"

            piece.Size = Vector3.new((size.X/pieces)+math.random(0.25,1), (size.Y/pieces)+math.random(0.25,1), size.Z)
    
            piece.CFrame = part.CFrame * CFrame.new(math.random(-size.X, size.X)/1.5, math.random(-size.Y,size.Y)/1.5, 0)

            piece.Color = part.Color

            piece.Transparency = part.Transparency

            piece.Anchored = true

            piece:ApplyImpulse(part.CFrame.LookVector * 50)---- delete if you dont want the pieces to fling slightly
        end

        part:Destroy()

    end
end

createPieces(script.Parent)
2 Likes

You forgot to parent the piece variable to something.

1 Like

local piece = Instance.new(“Part”, workspace)

2 Likes

Oh my bad (I never really use the second argument haha), also you shouldn’t use the second argument, it has performance amplifications.

Here’s the post by the staff (If you’re interested):

2 Likes

Oh ok. I’ve used it for many years as a line saver lol. Thanks for the info!

2 Likes

It’s not exactly what you want, but I found these posts for breaking parts into triangles instead of blocks:

For blocks, the easiest option would be to pick a line to divide the part along a single axis, once. Then do the same for each of the two halves. Repeat until you have the number you’d like. Would be okay for most visual purposes and be easy to implement.

3 Likes

This is a promising approach for a slightly more random layout: geometry - Has anyone ever attempted to find all splits of a rectangle into smaller rectangles? - Mathematics Stack Exchange

1 Like

o wow woke up to a lot of responses lol. I’m gonna try some of this stuff out. I’ll update you on how it goes.

Greatly appreciate the help.

I can think of 2 approaches to this.

The first one would basically be manually splitting up the windows and walls, and when they get broken, unanchor each piece and use bodyforces to make them fly out.

The second method would be actually scripting it to be shattered into customizable amounts of pieces. The first problem of this would how to actually do it; It’d definitely require a lot of math and thinking. The second problem with this is the shape of the pieces. If you had more than just cubes, say wedges, then it’d make things even more complicated.

1 Like

This almost works.
The only issue is that the pieces dont actually fill up the window.

the manual method isn’t the best for me. I’m going to have destructible buildings in my game so I dont think it would be too performance friendly if every single part had X amount of little parts in it.

this is EXTREMELY promising.
I tried to use part fracturing system v3 but it requires parts to be positioned a certain way so that wont work for my game.

I tried FragmentSmasher and this is the very promising result I received.
https://gyazo.com/571cd25bc520efcbbdc59883f59d614e

As you can see though there is ONE small issue.
The fragments are always positioned in the same direction. If I can fix that. This would be perfect.
I’m assuming it has something to do with this part of code in the script.

local function CreateQuadrants()
        local Quadrants = {}

        local Region =
            Region3.new(
            Vector3.new(CenterPos.X, CenterPos.Y, CenterPos.Z),
            Pane.Position + Vector3.new(Pane.Size.X / 2, Pane.Size.Y / 2, 0)
        )

        local QuadrantA = Instance.new("Part")
        QuadrantA.Anchored = true
        QuadrantA.CFrame = Region.CFrame
        QuadrantA.Size = Vector3.new(math.abs(Region.Size.X), math.abs(Region.Size.Y), math.abs(Pane.Size.Z))
		QuadrantA.Parent = workspace

        QuadrantA.Transparency = Pane.Transparency
        QuadrantA.Reflectance = Pane.Reflectance
		QuadrantA.Color = Pane.Color
		QuadrantA.Material = Pane.Material
        table.insert(Quadrants, QuadrantA)

        local Region =
            Region3.new(
            Pane.Position + Vector3.new(Pane.Size.X / -2, Pane.Size.Y / -2, 0),
            Vector3.new(CenterPos.X, CenterPos.Y, CenterPos.Z)
        )

        local QuadrantB = Instance.new("Part")
        QuadrantB.Anchored = true
        QuadrantB.CFrame = Region.CFrame
        QuadrantB.Size = Vector3.new(math.abs(Region.Size.X), math.abs(Region.Size.Y), math.abs(Pane.Size.Z))
        QuadrantB.Parent = workspace

        QuadrantB.Transparency = Pane.Transparency
        QuadrantB.Reflectance = Pane.Reflectance
        QuadrantB.Color = Pane.Color
		QuadrantB.Material = Pane.Material
        table.insert(Quadrants, QuadrantB)

        local Region =
            Region3.new(
            Vector3.new(CenterPos.X, CenterPos.Y, CenterPos.Z),
            Pane.Position + Vector3.new(Pane.Size.X / 2, Pane.Size.Y / -2, 0)
        )

        local QuadrantC = Instance.new("Part")
        QuadrantC.Anchored = true
        QuadrantC.CFrame = Region.CFrame
        QuadrantC.Size = Vector3.new(math.abs(Region.Size.X), math.abs(Region.Size.Y), math.abs(Pane.Size.Z))
        QuadrantC.Parent = workspace

        QuadrantC.Transparency = Pane.Transparency
        QuadrantC.Reflectance = Pane.Reflectance
		QuadrantC.Color = Pane.Color
		QuadrantC.Material = Pane.Material

        table.insert(Quadrants, QuadrantC)

        local Region =
            Region3.new(
            Vector3.new(CenterPos.X, CenterPos.Y, CenterPos.Z),
            Pane.Position + Vector3.new(Pane.Size.X / -2, Pane.Size.Y / 2, 0)
        )

        local QuadrantD = Instance.new("Part")
        QuadrantD.Anchored = true
        QuadrantD.CFrame = Region.CFrame
        QuadrantD.Size = Vector3.new(math.abs(Region.Size.X), math.abs(Region.Size.Y), math.abs(Pane.Size.Z))
        QuadrantD.Parent = workspace

        QuadrantD.Transparency = Pane.Transparency
        QuadrantD.Reflectance = Pane.Reflectance
		QuadrantD.Color = Pane.Color
		QuadrantD.Material = Pane.Material

        table.insert(Quadrants, QuadrantD)

        Pane:Destroy()

        return Quadrants
    end

CenterPos is the origin of the break. (Where the crack starts)
Pane is the part being destroyed.

I’ve customized the script a bit to fit some things I want but still having trouble making it fit the entire part.
It has something to do with this part of the region3

 Pane.Position + Vector3.new(Pane.Size.X / 2, Pane.Size.Y / 2, 0)

That causes the issue where its always angled the same. Not sure how to fix it.

I will mark you as a solution. In FragmentSmasher some kind person actually left some code to adjust the position to fix the problem.

1 Like