Answers for "check collision force unity"

C#
3

how to detect collision in unity

void OnCollisionEnter(Collision collision)
{
	if(collision.gameObject.tag == "yourNameOfObject")
    {
    	//This is example
        Debug.Log("Hit Object");
        //code your thing here
    }
}
Posted by: Guest on August-03-2021
1

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;
    }
}
Posted by: Guest on June-21-2020

C# Answers by Framework

Browse Popular Code Answers by Language