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 done than said.
-
First things first, get your module and store it in a necessary place, such as ServerScriptService
-
Create an object that will be used for the system. I’ll be using a transparent pane.
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:
-
This isn’t required, but if you want a sound to play when the object fractures, you can insert a Sound called BreakingSound into your object.
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!