Damaging a car depending on force of impact.

Basically what the title says; I have a car, and i want it to take damage when the colliders of the car hit the ground. Depending on the force of impact, or velocity, i want it to take more or less damage. I tried searching around, but didn’t find anything.

Could someone point me in the right direction, any help is greatly appreciated,

Cheers!

You could use Collision.relativeVelocity : here’s the link

Using this you can calculate the relative velocity between the car and the object that the car has collided with. Then you gotta use a mathematical constant to find out how much damage you have to apply to the car. Let me write an example : In this example the car takes no damage if the relative velocity is less than 10 and if more that 10 then it suffers damage. You you want the car to take damage even if the relative velocity is less that 10 then remove that lines in have commented as “remove this” :

var damageConstant : float;
var carHealth : float;

function OnCollisionEnter( col : Collision ){

    if(col.relativeVelocity.magnitude > 10){ //remove this 

        carHealth -= damageConstant * col.relativeVelocity.magnitude ; //line 1

    }  //remove this

    if ( carHealth < 0 ){

        destroyCar();

    }

}    

function destroyCar(){

    //instantiate some fancy particle system for special effects
    //and maybe instantiate a heavily damaged car on its place
    Destroy(gameObject);  //destroy our car
}    

You will have to change the value of damageConstant and also maybe carHealth to get better results. By changing them you can change the amount of damage that the car can take before getting destroyed.

I Hope this helped!