Question by 
               $$anonymous$$ · Jun 21, 2016 at 03:25 AM · 
                unity 5collideraiontriggerenterother  
              
 
              How to check for collisions only with certain colliders on a gameobject?
I have a problem with my collision detection for my AI. AI controlled enemies in the game have a single capsule collider on their body that is meant to detect collisions, and if there is a collision, then it subracts hp. Unfortunately, since the enemy has a golf club that it uses as a weapon (which also has a collider), collisions with the golf club also register in the code below. How do I get collisions from only the collider that I want?
 void OnTriggerEnter(Collider other) {
             if ((other.gameObject.transform.root.gameObject.tag == "Player")&&(other.gameObject.transform.root.gameObject.GetComponent<controls>().primary))
             {
                 hostile = true;
                 if (other.gameObject.tag == "fist") {
                     hp -= 5;
                 }
                 if (other.gameObject.tag == "golfclub") {
                     hp -= 10;
                 }
             }
 }
               Comment
              
 
               
              $$anonymous$$ay LayerBasedCollision be helpful in your need.
Not exactly. The weapons are interchangeable between the player and the ai enemy.
never $$anonymous$$d, it seems to work
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                