How to calculate improved car impact damage value?

Getting the value of impact is easy: using the relativeVelocity of the Collision field in

void OnCollisionEnter(Collision col){ 
    impactSpeed = col.relativeVelocity.magnitude;
    //do further instructions with impactSpeed...

Done. But, since I am writing here, you anticipate that this is not the best approach.


The problem with having only col.relativeVelocity.magnitude as your damage source is that you wreck your car when you are touching a wall at the side of it and maintain driving.


That is caused since it will return the cars velocity because the wall has no velocity (static).


Obviously the wanted damage should be low due to no/minimal velocity loss.


But substracting the cars’ velocity to correct that doesnt help, it will give a value that is not lim->0.

impactSpeed = (col.relativeVelocity - rb.velocity).magnitude; //should equal to rb.velocity - rb.velocity with non rigidboy collisions and (2*rb.velocity) - rb.velocity if 2 cars are colliding with same speed

So how to give a higher damage when the crash would stop the car more than a bump?

Is there an accurate formula for that?

In my damage system, to get around that issue I took the absolute dot product of the relative velocity with the collision’s hit normal and adjusted the impact based on that (that way objects colliding towards each other will do significantly more damage than those that are adjacent to each other), i.e.

impactSpeed = col.relativeVelocity * Mathf.Abs (Vector3.Dot (col.relativeVelocity.normalized, col.normal));

I then just played around with some static modifiers until it looked decent.