How do i make a breakable glass

This person seemed to have an interesting way to do it:

1 Like

Yes we can actually break the glass with a gun

2 Likes

Listen to other people first I am no scripter so I am just guessing lol

is there more sensible way? cause ı cant understand this

Can you write the example code of breaking physics?

There isn’t any physics in place to break a part into pieces. Someone made a simple fracture module.

When programming something, you need to determine the information you need and the result you want. There are two ways to do this. You can either have the glass break at an exact point (in which case you’d need the point where the glass should break) or you’d just have it break. You also need to know when you want it to break. It make it work with existing code you’re probably going to need to add a humanoid to the glass. Then connect the died event to the break function.

To help us help you, it’d be nice if told us:

  • Your programming experience
  • What you want in more detail
  • Important information (like what you want to break the glass)
1 Like

more detail about of this system?

Does it matter where the glass breaks? When do you want it to respawn? What are you using to break the glass?

There are free models that do this BTW.

I’m no scripter, but I think it’s possible this way:

  1. Start with a big glass piece and some invisible, untouchable wedges of the same color and material.
  2. If the glass piece is touched, destroy the glass piece and make the wedges touchable and unanchored.
    It might work like this:
local GlassPiece = script.Parent
local Wedges = GlassPiece.Parent:GetChildren(GlassWedge)
GlassPiece.Touched:Connect(function()
     GlassPiece:Destroy()
     for i, v in pairs(Wedges) do
          v.Transparency = 0
          v.CanCollide = true
          v.Anchored = false
     end
end)

Anyway, that’s just my two cents.

1 Like

Wow it really makes sense
I didnt thinked this before its more easy and more open.

Howewer how can we break the glass with a gun?

Try changing how the glass breaking function is activated. It will work with projectiles, but likely not with raytracing-based guns.

1 Like

Tiling the part like in that example is probably one of the easiest ways to do it.

You can add a humanoid to the glass model (similar to a character) then connect the died event. That normally works with most free weapons.

can we add a bullet model to the guns and we shoot the bullet model will turn to the enabled mod
and we can add a script that is about when the bullet touched to the glass, then glass will broke

So what you can do is putting the glass into a 3d software, slicing it into pieces, importing the pieces and grouping them so the model looks like a clone of the un-sliced one, and writing a function. For example everytime you click the class the cancollide goes off, the transparency becomes one and the transparency of the pieces becomes 0 and their anchored goes off.

Hold on let me pull the code i used from my gun

1 Like

Can you write the script that you meant

heres what breaks it

local Module = require(script:WaitForChild("PartFractureModule"))
if hit.Material == Enum.Material.Glass then
	local attach = Instance.new("Attachment")
	attach.Parent = hit
	attach.Name = "BreakingPoint"
	attach.Visible = true
	local BreakingPoint = hit:FindFirstChild("BreakingPoint")
		if BreakingPoint and BreakingPoint:IsA("Attachment") then
			BreakingPoint.WorldPosition = position
			BreakingPoint.Position = Vector3.new(BreakingPoint.Position.X, BreakingPoint.Position.Y, BreakingPoint.Position.Z) 
			Module.FracturePart(hit)
		end
end

Keep in mind that this is from raycasting

5 Likes

Sure, you can use the BasePart.Touched event for that. That will only work though if you’re not setting the ballets position with CFrames.

If you’re making your own gun, I’d recommend connecting the event you use to control hits to a checker to see if the hit was a suitable glass model/part. You can then use the OS module I posted above and the position of the bullet (and some math) to find the fracture point and fracture the glass.