- Home /
A child component is triggering its parent collider.
Hi guys, I just created a box collider, marked it as a trigger, and attached it to an enemy. Now I can use it as a sensor to check if the player is inside the skeleton attack range. Everything working fine here.
The problem comes when the player attacks back. I use the same logic in the other side, a player with a box collider attached used as attack. But this attack collides with the skeleton sensor, so it triggers the getDamage() rutine in the enemy.
Is there a way to fix this, or am I aproaching this problem the wrong way? Thanks in advance!
Answer by jim3878 · Jun 11, 2018 at 10:22 AM
do you mean that skeleton can attack box collider of player?
if it's true.Add a tag in body collider of player(or skeleton).
void OnTriggerEnter(Collider other) {
if(other.tag=="player"){
//Damage code
}
}
Actually the problem is not the collider you called "other", but the collider asociated to the script. I found a guy with a similar problem and exposed it better than me :
https://answers.unity.com/questions/449121/child-collider-triggering-parent-collider-effects.html
Seems that it can be fixed by attaching a rigid body to the collider acting as a sensor.