- Home /
Headshot Collision
Basically I've got a zombie that only is effected by headshots, however when I have a bullet or ray or w/e collide with the object it pulls the parents tag not the tag from the head, (I have a collision attached to the head bone I want to be able to tell via tag if this is the part hit) how do I get it to pull the tag of the specific bone/body part it has hit?
Answer by Paparakas · Nov 21, 2013 at 11:12 PM
Ok so I actually know this one since I've had some frustrating moments with it in my own project.
If the parent is a rigidbody and the children are all exclusively colliders, it will act as a compound collider. You can look that up in the documentation. It basically just means a rigidbody comprised of multiple colliders.
Either way, if you were to cast a ray to any of the colliders within the compound collider, RayCastHit hit would give you the parent (the one with the rigidbody). If you want to get the individual colliders you'd do hit.collider.
I hope this helps at least somewhat.
Thanks. That really helped me! Almost 5 years on.
Ironically your comment just pulled me back to this thread, and I'm about to do something similar again, which means this will help me immensely! thank you both!
Answer by jotaoliveira · Nov 04, 2018 at 02:05 PM
After some research, I've found an easy way to do this without any workarounds.
When creating Colliders, use different names in each of them, as head, torso, legs, arms. Then on OnCollisionEnter method, you just had to check all of the contact points.
void OnCollisionEnter(Collision col)
{
foreach (ContactPoint contact in col.contacts)
{
Debug.Log(contact.thisCollider.name + " hit " + contact.otherCollider.name);
if (contact.thisCollider.name == "HitBoxHead") {
Debug.Log("Head Shot");
}
}
}
Answer by bilo-lwabona · Nov 21, 2013 at 08:06 PM
I am not sure how one would achieve what you are trying to do in that exact way, but let me provide a close enough alternative:
You could attach a gameObject with a collider to the head portion of the mesh, where the collider is a close enough fit. Then you could assign the desired tag to the "collider gameObject" and should be able to perform the head shot detection on that.
I presume you would want to have multiple zombies, so you could create a prefab for this, meaning you would only have to set it up once and instantiate the prefab each time a zombie is created.
Hope this helps.
Cheers
Bilo
Ok Well I did that, same problem happeneds, it just goes to the highest up on the parent list, I don't know why.
Your answer
![](https://koobas.hobune.stream/wayback/20220613122431im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Allow picked up object to collide with game level GameObjects 1 Answer
C# How to have weapon pickup 1 Answer
[Javascript] My script won't work.. 1 Answer
bullet desent seem to apear (javascript) 0 Answers
Why Is My Zombie Not Colliding? 4 Answers