How can I detecting in what way a part touched something

You can write your topic however you want, but you need to answer these questions:

  1. 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.
  2. 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
  3. 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? :slightly_smiling_face:

1 Like

I think the issue is that you’re telling the script to break the glass whenever the magnitude reaches >100,

this may be a hacky solution but you can make a loop after the glass reaches >100.

This loop will wait for the speed to drop below 100 and when it does the glass will break (the glass will stop moving when it ‘crashes’ right?)

May i also ask how this is being done, like how would the glass work in your game? does the glass have a chance to slow down?

I haven’t applied it to a game yet, but in the place I am testing it on, I put barriers on the edges. I will also try doing that.

I will tell you if it works, thank you! :grinning:

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

I tried doing this:

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?

Also, how do I upload a video or picture?

do you want the glass to break on a Specific part? you could input the script to detect the glass instead of the glass detecting the part

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?

it printed 105 yet you told to script for it to be less than 25, so it didn’t break

you threw it off a high place, which means it won’t slow down until it impacts the floor

I tried testing it again and it did not print anything when it was touched so I am not sure if it will work.

did you change anything in the script?

This is the script now:

--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)

Maybe BasePart:GetTouchingParts (roblox.com) would help?

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

I think I am going to try that on a invisible box (with CanCollide = false) that will detect the collisions. :slightly_smiling_face:

Alright then, good luck with that!

I got it to work! Thank you for your help! :smiley: :dog: :bear:

This is the script:

script.Parent.TouchSensor.Size = script.Parent.Glass.Size + Vector3.new(0.125, 0.125, 0.125)
script.Parent.TouchSensor.Position = script.Parent.Glass.Position
script.Parent.TouchSensor.Touched:Connect(function(touched) 
	
		
	if math.abs((script.Parent.TouchSensor.AssemblyLinearVelocity - touched.AssemblyLinearVelocity).Magnitude) >= 50 then
		
		wait(0.5)
		
		if math.abs((script.Parent.TouchSensor.AssemblyLinearVelocity - touched.AssemblyLinearVelocity).Magnitude) <= 25 then
			BreakGlass(script.Parent.Glass, script.Parent.Glass.Position)
		else 
			
		end
		
	end
end)

glad it worked for you! and i’m glad that i could help