Skip to main content
added 46 characters in body
Source Link
Justin Markwell
  • 2.2k
  • 2
  • 14
  • 16

I like toYou can perform a check on the collision Contact point. then you canand see which hit box was hit and also get the point of impact if needed. You can check against layers tags or however you prefer

note: the rigidbody is placed on the same object that has the Collision Check script. I check against a hitbox name in this

This example is checking to see which hitbox the 'projectile' hit on a target.

private void OnCollisionEnter(Collision othercollision)
{                 
        if (othercollision.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")
             enemy.HeadShot = true;  
       //DO STUFF            

    if (othercollision.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
            enemy.BodyShot = true; //DO STUFF    
}

I like to perform a check on the collision Contact point. then you can see which hit box was hit and get the point of impact. You can check against layers tags or however you prefer. I check against a hitbox name in this example.

private void OnCollisionEnter(Collision other)
{                 
        if (other.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")
             enemy.HeadShot = true;
        if (other.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
            enemy.BodyShot = true;      
}

You can perform a check on the collision and see which hit box was hit and also get the point of impact if needed.

note: the rigidbody is placed on the same object that has the Collision Check script.

This example is checking to see which hitbox the 'projectile' hit on a target.

private void OnCollisionEnter(Collision collision)
{                 
    if (collision.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")                
       //DO STUFF            

    if (collision.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
       //DO STUFF    
}
deleted 55 characters in body
Source Link
Justin Markwell
  • 2.2k
  • 2
  • 14
  • 16

I like to perform a check on the collision Contact point. then you can see which hit box was hit and get the point of impact. You can check against layers tags or however you prefer. I check against a hitbox name in this example.

private void OnCollisionEnter(Collision other)
{                 
        ContactPoint contact = other.contacts[0];
        if (other.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")
            enemy.HeadShot = true;
        if (other.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
            enemy.BodyShot = true;      
}

I like to perform a check on the collision Contact point. then you can see which hit box was hit and get the point of impact. You can check against layers tags or however you prefer. I check against a hitbox name in this example.

private void OnCollisionEnter(Collision other)
{                 
        ContactPoint contact = other.contacts[0];
        if (other.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")
            enemy.HeadShot = true;
        if (other.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
            enemy.BodyShot = true;      
}

I like to perform a check on the collision Contact point. then you can see which hit box was hit and get the point of impact. You can check against layers tags or however you prefer. I check against a hitbox name in this example.

private void OnCollisionEnter(Collision other)
{                 
        if (other.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")
            enemy.HeadShot = true;
        if (other.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
            enemy.BodyShot = true;      
}
Source Link
Justin Markwell
  • 2.2k
  • 2
  • 14
  • 16

I like to perform a check on the collision Contact point. then you can see which hit box was hit and get the point of impact. You can check against layers tags or however you prefer. I check against a hitbox name in this example.

private void OnCollisionEnter(Collision other)
{                 
        ContactPoint contact = other.contacts[0];
        if (other.contacts[0].otherCollider.transform.gameObject.name == "HeadShot")
            enemy.HeadShot = true;
        if (other.contacts[0].otherCollider.transform.gameObject.name == "BodyShot")
            enemy.BodyShot = true;      
}