How do i make a breakable glass

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.

Would this work?

local GlassPiece = script.Parent
local Wedges = GlassPiece.Parent:GetChildren(GlassWedge)
local Humanoid = script.Parent.Humanoid
Humanoid.Died:Connect(function()
     GlassPiece:Destroy()
     for i, v in pairs(Wedges) do
          v.Transparency = 0
          v.CanCollide = true
          v.Anchored = false
     end
end)
1 Like

I remember someone just talked about of the humanoid script before ,

Can you tell the algorithm of this script?

Yeah that looks good. Remember to organize it like this:

model

hittable part
humanoid

So that it’s similar to a normal character/rig.

This creates a attachment that is parented to hit then i just took the code they gave here

ı am wondering about the difference from the character/rig

A character is a player’s rig. A rig is a model with a humanoid and base parts inside of it, usually with an animator and constraints.

Edit:
A character is a rig, though rig isn’t super specific.

If we going to make this system in to the gun tool , then
Do we have to add this script in to the gun model?
Or in to the bullet model
Which ı just talked about of it before

And whats happen if we put this script in to both of them?

This script would go into the glass. You’d also need to format it correctly.

You could always just raycast to the glass pane from the barrel or (if using a crosshair that isn’t fixed) you could use CFrame:ToWorldSpace and raycast to there. Then you’d just fire an event when the glass connects with the raycast, you dont need a physical Touched part.

Well can you tell the algorithm of the physical touched part , ı mean can you tell me the logic of it?
And what is the most sensible way to make breaking glass.

Touched would just detect if your bullet that you’re presumably CFraming touched the glass, then you’d fire the event. The module mentioned above would work great for fragmenting it. However, Touched is not super performant, so I’d recommend firing a raycast from the gun outwards (which you’re probably already doing since it is a gun), detect if the part that it intersects is glass, and then you can fire your fragmentation script.

1 Like