I’m trying to get the force of a part to see how powerfully it has hit another part, for example a car crashing into a wall. I’m trying to make crash physics but I have come across a bug?
Here’s my code I’m using:
local function onCollision(otherPart)
local impactThreshold = 1000
local velocity = Part.Velocity
local mass = Part:GetMass()
local impactForce = mass * velocity.Magnitude
if impactForce >= impactThreshold then
-- break welds
end
end)
Part.Touched:Connect(onCollision)
For some reason this doesn’t work on grouped parts, I’m not sure why?
Not entirely sure what you mean by grouped parts in this context, but I’ll provide some assistance anyway:
Your code only triggers when a part is directly touched by some object that wasn’t touching it before. Multiple parts in a car would all be touching even other constantly, however wouldn’t actually touch the object it collided with, meaning the code doesn’t fire.
Does my explanation makes sense in relation to the issue you are facing, or have I misinterpreted it? LMK and I can try to provide either an alternative explanation as to what happened, or I can try to provide a solution.