FractureGlass Module - Realistic Glass Breaking in Roblox

Module: https://create.roblox.com/marketplace/asset/14299460994

About:

Breaking glass in FPS games is satisfying. However, I noticed that there aren’t really any glass breaking modules on Roblox that look realistic. So, I made this module to make realistic glass breaking so it’s even more satisfying!

How to Use:

Put the module somewhere in ReplicatedStorage
You can technically put it in ServerScriptService or ServerStorage, but this module creates the fragments on the client to make the glass more responsive. If you do still choose to do this, set replicate to false in the module. When you want to break the glass, call the module:

local FractureGlass = require(game.ReplicatedStorage.FractureGlass)
FractureGlass(part, origin, force)

--[[
	part: BasePart
		The glass we want to fracture
	origin: Vector3?
		The center point of where the glass will break
		Default: part.Position
	force: Vector3?
		The velocity that will be applied to the glass fragments
		It's highly recommended that you use this parameter so the glass can fall more easily
		Default: Vector3.zero
]]

Inside the module, there are many settings you can play around with. I recommend that you try to keep the number of fragments minimal to minimize lag.

82 Likes

Simple and easy to use, lovely module! :heart_decoration:

2 Likes

this is SOOOOOOO great!!! i needed this for so long

1 Like

YOOOOOOOOOOOO i wanted something like that for a loooong time, and now it’s here, but I have an idea, would you make it so it would work with multiple parts?

1 Like

Why not just apply the function on the multiple parts? You can set the origin to be outside of the glass, so it will still work just fine. However, you might notice more triangles near the edges of the part because I have to triangulate all of the quads after clipping them. However, I don’t really think that would matter that much since the effect only lasts a couple seconds.

2 Likes

Is the sound in the video automatically played by calling the function? If so, I would like the option to customize it.

1 Like

Yes. You can set the soundId and soundVolume in the module settings, and you can set the soundId to 0 if you don’t want any sounds.

1 Like

2 feature ideas

Possibly an option for the shards to tween out, instead of the instant pop out, either tween the size, or transparency

Possibly an option to choose how many shards spawn? More shards near the origin point?

1 Like

cuz I don’t want to make a million scripts or one big script that does the job

I think this would be a cool addition to add to the module.

In the module settings, you can customize how many triangles are generated. The way it works is that the cracks change direction after it reaches a radius. This radius is determined by the diameter variable, and it gets multiplied by the multiplier variable after the we reach the radius. The number of cracks we have is determined by the numCracks variable, and each crack is connected to the neighboring cracks at the radii. These form quads and are then clipped if they go outside the glass borders, and everything gets triangulated. I set these variables to minimize lag while still looking good since you have to keep in mind that increasing the number of triangles will increase the number of unanchored parts being added to the game which will contribute to a lot of lag if you break a lot of glass all at once.

How exactly are you planning to call this function? Are you going to have a script for each glass object or something? I was thinking you would have a single script that handles all of the glass breaking, and you could just write a loop that will call the function for each part you want to fracture at once.

1 Like

Update:
This plugin can now fracture wedges properly!
You can also apply tween effects to the glass fragments as well!

1 Like

Read about CollectionService and its usage on repeated parts that achieve the same functionality.

I understand about collection service but not every part I want would be in one collection service tag

1 Like

@MrTumbleWede TumbleWede This is good, but how to make the part respawn after 5 seconds? I made a system, but it only makes the part respawn without the module working. Here is my script

local FractureGlass = require(game.ReplicatedStorage.FractureGlass)

local function onPartTouch(otherPart)
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local part = script.Parent 
		local origin = part.Position 
		local force = Vector3.new(0, -9.81, 0) 
		FractureGlass(part, origin, force)
		game.SoundService["Glass breaking"]:Play()
	end
end


script.Parent.Touched:Connect(onPartTouch)    

1 Like

You should probably make a copy of the part before you call the FractureGlass function.
Also instead of playing the glass break sound manually, you can just set soundId in the module.
It seems like you are trying to destroy the part that the script is parented to. I recommend you don’t do that because the script will be destroyed with the part.

local FractureGlass = require(game.ReplicatedStorage.FractureGlass)
local part = script.Parent.Part -- Assuming part and script are under the same parent
local debounce = false

local function onPartTouch(otherPart)
	if debounce then return end
	local partParent = otherPart.Parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")

	if humanoid then
		debounce = true
		local newPart = part:Clone()
		newPart.Parent = script.Parent
		-- Make the part disappear
		part.Parent = game.ServerStorage
		local origin = part.Position 
		local force = Vector3.new(0, -9.81, 0)
		-- We fracture a fake part instead so we don't destroy the normal part
		FractureGlass(newPart, origin, force)
		task.wait(5)
		-- Make the part reappear
		part.Parent = script.Parent
		debounce = false
	end
end

part.Touched:Connect(onPartTouch)  

I haven’t tested this code but hopefully it gives you a good idea.

1 Like

Thanks, I made the script in ServerScriptService and applied your advice. Now it works, but for the soundId in the module, I tried and the ID was not detected, and I did not figure out how to that why i did it this way.

can you break the glass by running into it

If you program it to then yes, its just a module to fracture the glass

1 Like

same issue here. The sound doesnt work. I might have a look into the problem later