Hi,
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?