You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I am trying to make a glass part shatter if it crashed but not slid against a part.
I know how to make it shatter, but I don’t know how to make it like real glass where it breaks when it crashes.
What is the issue? Include screenshots / videos if possible!
It runs when it slides and crashes, but I want it to only run if it crashed, like real glass
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried doing this:
script.Parent.Glass.Touched:Connect(function(touched)
if math.abs((script.Parent.Glass.AssemblyLinearVelocity - touched.AssemblyLinearVelocity)).Magnitude > 100 then
--Break the glass
end
end)
But it also runs if it is sliding across a part.
Is there any method or way to detect when it crashes?
Alright, do note that my method may not work if the glass has a chance of slowing down, if the glass slows down then the glass will break while slowing down
local db = true
script.Parent.Glass.Touched:Connect(function(thing)
if math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude) >= 50 and db then
print(math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude))
db = false
wait(0.1)
print(math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude))
if math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude) < 25 then
-- Break the glass
else
db = true
end
end
end)
But then it printed:
83.240257263184
105.90544891357
(Most likely because it bounced)
But then it sometimes goes less, so should I check if it goes slower or faster?
To test it, I pushed it off a high place, but I notice that when it hit the ground, it did not sense the touch. Do you know how I make it sense the touch?
--local db = true
script.Parent.Glass.Touched:Connect(function(thing)
if math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude) >= 50 and db then
print(math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude))
--db = false
wait(0.1)
print(math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude))
if math.abs((script.Parent.Glass.AssemblyLinearVelocity - thing.AssemblyLinearVelocity).Magnitude) > 75 then
BreakGlass(script.Parent.Glass, script.Parent.Glass.Position)
else
--db = true
end
end
end)
Basically, you can use this to return a table of things that are touching the part, so after the glass reaches the desired destroying speed, they can check which part is touching them, then you may “whitelist”
any parts that you want the glass to be destroyed by