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
}
}
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
}
}
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;
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us