Part fracturing system V3

As we all know, destruction is a nice thing. Everyone loves a bit of destruction here and there. To make things better for our world, I introduce you to do this part fracturing system that is free to use!

What is this system?

This system is an easy to set-up module that allows you to make any blocks destructible!

Here are some examples!

Launching a ball at glass

Ball code
local Ball = script.Parent
local SSS = game:GetService("ServerScriptService")
local Module = require(SSS:WaitForChild("PartFractureModule"))

Ball.Touched:Connect(function(PartToFracture)
	local BreakingPoint = PartToFracture:FindFirstChild("BreakingPoint")
	if BreakingPoint and BreakingPoint:IsA("Attachment") then
		BreakingPoint.WorldPosition = Ball.Position -- Move the BreakingPoint to where the ball hit
		BreakingPoint.Position = Vector3.new(0, BreakingPoint.Position.Y, BreakingPoint.Position.Z) -- make sure the attachment is within its part

		Module.FracturePart(PartToFracture)
	end
end)

Dropping a glass pane

Glass pane code
Part = script.Parent

SSS = game:GetService("ServerScriptService")
FractureModule = require(SSS:WaitForChild("PartFractureModule"))

Part.Touched:Connect(function()
	FractureModule.FracturePart(Part)
end)

Wrecking ball

Wrecking ball code
local Ball = script.Parent
local SSS = game:GetService("ServerScriptService")
local Module = require(SSS:WaitForChild("PartFractureModule"))

Ball.Touched:Connect(function(PartToFracture)
	local BreakingPoint = PartToFracture:FindFirstChild("BreakingPoint")
	if BreakingPoint and BreakingPoint:IsA("Attachment") then
		BreakingPoint.WorldPosition = Ball.Position
		BreakingPoint.Position = Vector3.new(0, BreakingPoint.Position.Y, BreakingPoint.Position.Z)

		Module.FracturePart(PartToFracture)
	end
end)

Why this system?

Unlike a lot of systems, this system allows you to set an origin for the cracks in your object

This system also has many advantages to other system. Such as;
A few settings, how easy this is to use, the shards will keep its velocity when a part fractures, and the fact that this will work with any kind of blocks!

How does it work?

The fracturing effect for this system requires math and steps.

Where can I get this system?

You can get the module here:

asset:

Source code
-- Part fracturing system --

-- Version 3
-- Last updated: 31/07/2020

local Module = {}

DebugEnabled = false

Debris = game:GetService("Debris")

function Module.FracturePart(PartToFracture)
	
	local BreakingPointAttachment = PartToFracture:FindFirstChild("BreakingPoint")
	
	-- Settings
	local Configuration = PartToFracture:FindFirstChild("Configuration")
	
	local DebrisDespawn = false
	local DebrisDespawnDelay = 0
	local WeldDebris = false
	local AnchorDebris = false
	
	if DebugEnabled then
		local DebugPart = Instance.new("Part")
		DebugPart.Shape = "Ball"
		DebugPart.CanCollide = false
		DebugPart.Anchored = true
		DebugPart.Size = Vector3.new(0.5, 0.5, 0.5)
		DebugPart.Color = Color3.fromRGB(255, 0, 0)
		DebugPart.Position = BreakingPointAttachment.WorldPosition
		DebugPart.Parent = workspace
	end
	
	local BreakSound = PartToFracture:FindFirstChild("BreakSound")
	
	if BreakSound then
		local SoundPart = Instance.new("Part")
		SoundPart.Size = Vector3.new(0.2, 0.2, 0.2)
		SoundPart.Position = PartToFracture.Position
		SoundPart.Name = "TemporarySoundEmitter"
		SoundPart.Anchored = true
		SoundPart.CanCollide = false
		SoundPart.Transparency = 1
		local Sound = BreakSound:Clone()
		Sound.Parent = SoundPart
		SoundPart.Parent = workspace
		Sound:Play()
		Debris:AddItem(SoundPart, Sound.PlaybackSpeed)
	end
	
	if Configuration then
		DebrisDespawn = Configuration.DebrisDespawn.Value
		DebrisDespawnDelay = Configuration.DebrisDespawnDelay.Value
		WeldDebris = Configuration.WeldDebris.Value
		AnchorDebris = Configuration.AnchorDebris.Value
	else
		warn("The 'Configuration' is not a valid member of " .. PartToFracture.Name .. ". Please insert a 'Configuration' with the following values; 'DebrisDespawn' (bool), 'WeldDebris' (bool), 'DebrisDespawnDelay' (number/int)")
	end
	
	if not BreakingPointAttachment then
		warn("The 'BreakingPoint' attachment is not a valid member of " .. PartToFracture.Name .. ". Please insert an attachment named 'BreakingPoint'")
	end
	
	local BreakingPointY = BreakingPointAttachment.Position.Y
	local BreakingPointZ = BreakingPointAttachment.Position.Z
	
	local ShardBottomLeft = Instance.new("WedgePart")
	local ShardBottomRight = Instance.new("WedgePart")
	local ShardTopLeft = Instance.new("WedgePart")
	local ShardTopRight = Instance.new("WedgePart")
	
	local BreakSound = PartToFracture:FindFirstChild("BreakSound")
	
	-- Bottom Left
	ShardBottomLeft.Material = PartToFracture.Material
	ShardBottomLeft.Color = PartToFracture.Color
	ShardBottomLeft.Transparency = PartToFracture.Transparency
	ShardBottomLeft.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) - BreakingPointY, (PartToFracture.Size.Z / 2) + BreakingPointZ)
	local OldSizeY = ShardBottomLeft.Size.Y
	local OldSizeZ = ShardBottomLeft.Size.Z
	ShardBottomLeft.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY - (ShardBottomLeft.Size.Y / 2), BreakingPointZ + (ShardBottomLeft.Size.Z / 2))
	ShardBottomLeft.CFrame = ShardBottomLeft.CFrame * CFrame.Angles(math.rad(90), 0, 0)
	ShardBottomLeft.Size = Vector3.new(ShardBottomLeft.Size.X, OldSizeZ, OldSizeY)
	local ShardBottomLeft2 = ShardBottomLeft:Clone()
	ShardBottomLeft2.CFrame = ShardBottomLeft2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	-- Bottom Right
	ShardBottomRight.Material = PartToFracture.Material
	ShardBottomRight.Color = PartToFracture.Color
	ShardBottomRight.Transparency = PartToFracture.Transparency
	ShardBottomRight.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) + BreakingPointY, (PartToFracture.Size.Z / 2) + BreakingPointZ)
	ShardBottomRight.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY + (ShardBottomRight.Size.Y / 2), BreakingPointZ + (ShardBottomRight.Size.Z / 2))
	local ShardBottomRight2 = ShardBottomRight:Clone()
	ShardBottomRight2.CFrame = ShardBottomRight2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	-- Top Left
	ShardTopLeft.Material = PartToFracture.Material
	ShardTopLeft.Color = PartToFracture.Color
	ShardTopLeft.Transparency = PartToFracture.Transparency
	ShardTopLeft.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) + BreakingPointY, (PartToFracture.Size.Z / 2) - BreakingPointZ)
	local OldSizeY = ShardTopLeft.Size.Y
	local OldSizeZ = ShardTopLeft.Size.Z
	ShardTopLeft.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY + (ShardTopLeft.Size.Y / 2), BreakingPointZ - (ShardTopLeft.Size.Z / 2))
	ShardTopLeft.CFrame = ShardTopLeft.CFrame * CFrame.Angles(math.rad(90), 0, 0)
	ShardTopLeft.Size = Vector3.new(ShardTopLeft.Size.X, OldSizeZ, OldSizeY)
	local ShardTopLeft2 = ShardTopLeft:Clone()
	ShardTopLeft2.CFrame = ShardTopLeft2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	-- Top Right
	ShardTopRight.Material = PartToFracture.Material
	ShardTopRight.Color = PartToFracture.Color
	ShardTopRight.Transparency = PartToFracture.Transparency
	ShardTopRight.Size = PartToFracture.Size - Vector3.new(0, (PartToFracture.Size.Y / 2) - BreakingPointY, (PartToFracture.Size.Z / 2) - BreakingPointZ)
	ShardTopRight.CFrame = PartToFracture.CFrame * CFrame.new(0, BreakingPointY - (ShardTopRight.Size.Y / 2), BreakingPointZ - (ShardTopRight.Size.Z / 2))
	local ShardTopRight2 = ShardTopRight:Clone()
	ShardTopRight2.CFrame = ShardTopRight2.CFrame * CFrame.Angles(math.rad(180), 0, 0)
	
	local ShardDictionary = {ShardBottomLeft, ShardBottomLeft2, ShardBottomRight, ShardBottomRight2, ShardTopLeft, ShardTopLeft2, ShardTopRight, ShardTopRight2}
	
	
	local FirstShard = nil
	for Index, Shard in ipairs(ShardDictionary) do
		if not FirstShard then
			FirstShard = Shard
		end
		Shard.Anchored = AnchorDebris
		if not AnchorDebris then
			Shard.Velocity = PartToFracture.Velocity
			Shard.RotVelocity = PartToFracture.RotVelocity
		end
		if WeldDebris and FirstShard then
			local Weld = Instance.new("WeldConstraint")
			Weld.Name = "ShardWeld"
			Weld.Part0 = FirstShard
			Weld.Part1 = Shard
			Weld.Parent = Shard
		end
		Shard.Name = "Shard"
		Shard.Parent = PartToFracture.Parent
		if DebrisDespawn then
			Debris:AddItem(Shard, DebrisDespawnDelay)
		end
	end
	PartToFracture:Destroy()
	
end

return Module

-- System by Ethanthegrand14

And you can get an uncopylocked test place here:

How do I set it up and use it?

Setting up the system is easier said than done.

  1. First things first, get your module and store it in a necessary place, such as ServerScriptService
    image

  2. Create an object that will be used for the system. I’ll be using a transparent pane.
    image
    you will also need to insert an Attachment called BreakingPoint inside your part.


    this attachment will be your fracture origin or breaking point.
    (this attachment can go anywhere, im just putting it in the corner for the sakes of demonstation)
    Next thing you’ll need to do is insert a Configuration folder that will contain your settings with the following values:
    image

  3. This isn’t required, but if you wan’t a sound to play when the object fractures, you can insert a Sound called BreakingSound into your object.
    image

Your system should now be ready for use!

To use your system, you will need to require the module and fire its fracture part function

Example
Part = script.Parent -- Your part you want to fracture

SSS = game:GetService("ServerScriptService") -- The storage
FractureModule = require(SSS:WaitForChild("PartFractureModule")) -- The module

FractureModule.FracturePart(Part) -- Shatter the part

Let me know what you guys think of this system.

Enjoy!

83 Likes

Now that’s a lotta damage pretty cool! When I saw this I think of that Rolling Sky game on the App Store, and this could definitely be used to make that sort of game. Pretty :fire: release!

6 Likes

hey can i tell you that did the balls need something that can destruct the glass

Yes, if you look at the examples and under the videos, there are the source codes for the objects used in the examples.

If you want a crack to appear on an object depending where you hit it, you will need to move the breakingpoint attachment to the position of where you hit the object and then run the FracturePart function

1 Like

Please can you provide the source code in the post (if not exceeding character limits) or in a pastebin so people merely browsing can take a look at your code easily.

1 Like

i was wondering where do i put the glass plane code on?
is it gonna be in breakePoint (attacment), Configuration or three of each value?

I was going to do that, but I didn’t have access to my computer half way through making this tread. I’ll add the source code soon once I get my PC back.

1 Like

Are you talking about the module? Or the script to active the fracture function
If either, it really doesn’t matter

If you are new to scripting and you are not sure what to do, then I recommend you go to that test place and edit it by clicking the three dots in the top right corner, and then edit place.

1 Like

can you show me a picture what inside of the ball?

There’s nothing inside the ball, except for a script. Which just simply actives the fracture function for the breakable glass upon impact.

should the glass need to anchor or not?
and i have issue with your part fracture

It doesn’t really matter if the part is anchored, it should work anyway.

And what’s wrong with the fracturing system?

Do you think there would ever be an update, maybe the velocity of the wrecking ball effects how far the glass pieces travel? Overall really good work :+1:

2 Likes

Possibly. That might be a thing in the V2.
Thanks for the idea!

No problemo :+1:
(30 charactersssssssss)

1 Like

maybe add an option to control the amount of debri that forms, and maybe if smoke happens, overall, amazing system, good job

1 Like

Can’t really do due to how the system works, and the fact that my scripting skill is pretty limited.

I’ll need to learn how to divide wedges into more wedges if you wan’t that to be a thing.

You can easily add that on yourself

Thanks for your feedback! :+1:

Update V2

This is just a small update that consists of improvements for the system and the thread itself.

Additions:

  • The debri/shards will now keep their velocity.

Improvements:

  • Optimized the system a bit.

Side notes:

  • The thread for this system has been updated as well. Such as adding the source code on the thread as @LuaBearyGood suggested
3 Likes

This looks very cool but how would this go for fracture effects on walls or wooden barricades?

One of my games is in need to replacing it’s fracture system based on several small anchored parts and could really use a system like yours.

What I am trying to understand is how I can make your fracture system work in away based on caliber, multiple hits before breaking and for example instead of fracture having actual bullet holes based on small caliber guns.

1 Like

Not really sure what your asking here.

on large walls, you’ll get big wedges. But if you wait till V3, the wedges from the fractured parts will break into smaller pieces as well, so you get more debris/rubble.

I haven’t tested fracturing on planks. I imagine it would like quite nice actaully.

You can achieve that by giving the object like a hit points value. And shooting it will take 1 away from that value. And if the value is 0 or below, you can run the fracture function.

And if you look at one of examples that uses the balls, you’ll see that they move the breaking point to where the ball hits. So if you want, you can do that to your gun as well.

1 Like