# How to get velocity before hit?

Im currently working on a game about destruction and i made some experiment with the touched event. I made various discoveries and i now know why scripts that use velocity to produce something on hit are sometimes broken. First off, the only thing that give you the possibility to get the velocity of an object when it get hit is the elasticity. What happen is when the object touch another object it bounces off with a fraction(depend on the elasticity level) of the velocity that it touched the object at. Now to properly read that you need to do calculation on the velocity because else if the elasticity is 0.5(half the velocity) then it will that it touched at 100s/s when it actually touched at 200s/s. Now your maybe asking to yourself Â« where is the problem then? Â».

The problem come from a lot of thing like if the elasticity is 0 then you wont be able to get it or even when the object rotate when touching something, it slow it down and return the wrong velocity. So i would need to find a way to get the correct velocity at which the object touched something but i seem to not be able to figure it out by myself.

I found a post about an unanchored part velocity tracker but i am a little worried by the impact on performance it could have including all other fracture and deformation scripts.

1 Like

You could check for the velocity of a part each certain amount of time, although this could present some performance issues. If itâ€™s some kind of vehicle, you could have a single part on each side, checking the velocity frequently and saving it to a variable. When a â€ścrashâ€ť or impact happens, the variable could be read. If possible, this would be useful to save before every physics frame.

1 Like

I will try doing that and optimizing it to the maximum to see if the the performance is will not be a problem. If it is then i would need to find another solution.

1 Like