Ok so for a long time I have been wondering how to make glass that can break when it is shot or hit with a certain speed… So I was wondering if anyone knew how to make glass that…
Breaks at a certain speed
Can be Shot or struck and break
If Shot struck or hit breaks into smaller fragments
The glass regenerates with no glass debris after a certain amount of time so it looks normal
It looks like its just a normal sound being played when the fracturing is triggered.
Im assuming you really want to know how to actually program the code to break in the first place. What I did is use the new live CSG code to recursively split each in half at a random angle. To make it pop in fast it is generated during the game intermission and just parented when the “Hold E” is completed.
“Breaks at certain speed” can be done simply by binding .touched and checking for Instance.Velocity.
About shattering the glass itself,
it looks like random Wedges are generated in the same position as the part before breaking.
Can’t really go in-depth about that yet as I have never done something like that before,
but you could possibly make 2 or 3 preset “Shattered glass” models and have a math.random decide which to spawn in place of your glass that’s being shattered.
The hardest part for me was generating the glass fragments. That’s when I learned how to do it online where the articles I studied are kinda long forgotten unfortunately.
These fragments are all just 2 wedge parts welded to each other. The shatter point is the origin and then from there it defines a boundary region (aka the whole glass part’s size). I then took a few points and placed them around the boundary, with a weight drawing it closer to the point of impact. That’s when I just did some triangulation and finally you have your glass shattering.
I also gave them a velocity based on a ratio between the edge of the part and the point of impact. The closer it is to the impact, the closer its velocity will be to that of the item that hit it.
Generate fragments like the above or use the realtime union functions to recursively cut objects. For the speed stuff you can do things like impact force detection by checking abrupt changes in velocity and calculating the acceleration between them