Detect collision of a child object with tag

Hello everyone, I want to detect the collision of a child object, for example I have a player object(parent) and contains the child objects which are the parts of the player(head,arms,legs…). I want to detect for example if my spear hits the head object which is child object and if does hit the head my player will die. I try to do the obvious technic:

if(collision.gameObject.tag == "Head")
        {
            Debug.Log("Enemy head");
            FindObjectOfType<EnemyAI>().playerHealth -= 100;
        }
        else
        {
            FindObjectOfType<EnemyAI>().playerHealth -= 50;
        }

But it doesn’t detect the tag.
BTW the script is attached to the spear object.

Make sure both spear and the head have a rigidbody component on it, even with “gravity = off” and “kinematic = on” , anddand try to write this “collision.transform.tag == Head” instead… (Or use the “CompareTag” that is better). if this doesn’t work make the head a trigger and use the “void OnTriggerEnter()”

Hope this help.

1 Like

make sure that all your child’s game objects have the tag that you are searching for and not the parent game object