unity get impact amount code example

Example: calculate impact damage + unity

//This is pulled direclty from the linked url, which is 100% worth a read if,
//like me your ripping this off.  Its a great article.

//This is an extension method for calculatin 2d Impact collisions and follow,
//the articles advice: To use this method create a file named 
//«Collision2DExtensions.cs» in your project, write 
//the previous code inside it and then use collision.GetImpactForce
// in your on collision enter method

public static class Collision2DExtensions {
    public static float GetImpactForce (this Collision2D collision) {
        float impulse = 0F;

        foreach (ContactPoint2D point in collision.contacts) {
            impulse += point.normalImpulse;
        }

        return impulse / Time.fixedDeltaTime;
    }
}