Detecting a .Touched event's hit force magnitude

Hello,
I’m trying to use the Hit force of a part on another object so I can determine whether to damage the object or not. For instance, two cars are speeding along. They crash head on. The Hit force is determined between the two bumpers and if the force is high enough they fall off. Currently, my system finds the magnitude of each part’s velocity, then subtracts the two of them to see what the difference is. Note: if the initial result is negative, it will switch the numbers and try again. After that, if the number is above, say 45, then it will activate my crumple script. The problem with my current solution is that, because magnitudes are always positive, I can’t tell if the two cars were heading in the same direction, a 90 degree angle, or head-on. Head-on collisions wouldn’t crumple the bumper because the magnitude is the same. Any ideas?

2 Likes

Just subtract them before you take the magnitude. The .magnitude is throwing away the very information that you want! (The direction the two objects are going in)

(script.Parent.Velocity - hit.Velocity).magnitude

This way, if the velocities are in the same direction, they will cancel eachother out, giving a very low speed. If they are going in opposite directions, they’ll add constructively and give you a very large difference. As it should—crashing head-on should do more damage than side-on.

11 Likes

Bit of an unrelated nit-picky thing for your issue but you should really capitalize the “t” in touched and the “c” in connect. I’m pretty sure connect, lower-cased, was deprecated a while ago.

3 Likes

Thanks! Ill try this as soon as I get on a computer and get back to you.