I have an enemy set up as a parent object with a rigid body and a box collider, when it collides with the player the player is killed, this all works fine. I wanted to add a second box collider to the enemy to serve as the ‘head’ so that if the player lands on the ‘head’ instead of the player being killed the enemy is destroyed.
I have setup the head as a child object to the parent with a box collider and nothing else. I am using:
OnCollisionEnter2D(Collision2D collision)
if (collision.gameObject.CompareTag(“Enemy Head”)) or (collision.gameObject.CompareTag(“Enemy Body”))
to try and differentiate the two box colliders with the parent object being tagged as ‘Enemy Body’ and the child object being tagged as ‘Enemy Head’ however when my player collides with the box collider of the child object (which has the tag ‘Enemy Head’ it is being treated as if its tag is set to ‘Enemy Body’. I watched a tutorial where somebody used this setup in 3D and it seemed to work fine, is there a reason it wouldn’t work in 2D?