- Home /
Do parent tags always affect children?
Hello, is this true, like i cannot have say AIObject with the tag "Zombie", and an sub object called headshothitbox and tag that as "Head". Every case where ive done this, i shoot the "Head" box and it returns the tag "Zombie"
case "Zombie":
Debug.LogError("BODY SHOT");
hit.transform.GameObject.GetComponent(Zombie).Health -= DamageToDeal;
Destroy(gameObject);
break;
case "Head":
Debug.LogError("HEAD SHOT");
hit.transform.GameObject.GetComponent(HeadShotDetector).Headshot = true;
Destroy(gameObject);
break;
I think the problem is getting the correct object. I believe that hit.transform
purposely returns the parent rigidbody, for compound colliders. And hit.collider
(?) returns the exact child. Try printing the name, the check this.
Answer by rezki · Jun 12, 2014 at 06:52 PM
change the tag of the body parts then change the tag of the head
By bodyparts you mean children? Are there a specific hirearchy i have to go with too? such as not having the hitboxes inside an object that has different tags to the ones i desire the hitbox to have?
For Example
AIObject
HeadHitbox - "Head"
Zombie$$anonymous$$odel - "Zombie"
Eyes
Blablabla
ins$$anonymous$$d of what i have currently
AIObject - "Zombie"
HeadshotBox - "Head"
Eyes
Zombie$$anonymous$$odel
Blablabla
var collidedRigidBody : Rigidbody = null; //don't modifie this
var BodyParts : Rigidbody[]; // Assign in the inspector all body parts and make sure that they all have RigidBodies "Head,Left Arm,LeftForeArm,RightArm,RightForeArm,all Spine1 Head and Leg bones "
function OnCollisionEnter (col : Collision) {
collidedRigidBody = col.RigidBody;
if(collidedRigidBody.tag == "Head"){
Debug.Log("HeadShot");
}
else{ // if i didn't shoot the head i shot the leg or the spine....
Debug.Log("BodyShot");
}
Assign this to your bullet prefab i modified my ragdoll Activator Script i used it to make ragdoll effect when i shoot the leg it swings back
Your answer
Follow this Question
Related Questions
problem with my simple script please help. 2 Answers
Pause menu make unity stuck 1 Answer
SmartFox Physics? 0 Answers
NullReferenceException on ThirdPersonControlller 1 Answer
NPC CharacterController doesn't move or stops randomly 0 Answers