Compound Collider Problem

Hi guys,

I have an enemy, that has two colliders:

  1. A SphereCollider that shall represent the enemy shape

  2. A BoxCollider, that shall work as its area of sight, as child

The enemy will be hit by a sword with a BoxCollider, that is a Trigger, and recognize this via:

function OnTriggerEnter(bla : Collider){
if(bla.tag == "sword"){
makeCrazyThings();
}
}

The problem is, that the enemy also receives this Collision Event, when I hit him at his “sight area” collider. He should only receive this Event when I hit him on its actual shape. Do you know how I can achieve this?

i don’t know the answer to that one, but id like to know the answer as well … my guess would be to just use one collider and adjust your enemy script

I’d know a possibility: Let the player send a message to the enemy via SendMessage() where he is told which collider was hit, and then he could react accordingly. But I don’t like this solution, because its requiring me to send a message to every enemy I hit -.- If the parameter in OnTriggerEnter() would only provide more information :-/

OnTriggerEnter gives you the Collider that entered your trigger. From that collider, you can get the gameObject that the collider is attached to, and from there you can get a reference to whatever script you have on that object to call a method on. Thus, you won’t need to use SendMessage and the message won’t go to every enemy at every hit.

From my experience, I believe the solution is to do something similar to the following:

* Enemy GO
| + AI Script
|
---- Sight GO
|    + Box Collider, Is Trigger = True
|    + Script to alert AI can see player
|
---- Hitbox GO
     + Box Collider, Is Trigger = False
     + Script to alert AI Damage

There might be a better way of designing this, but I’ve had more luck with small scripts than larger ones. I find them to be more reusable.

Hey thanks this works, but with a little change:

* Enemy GO 
| + AI Script 
*| + Rigidbody, isKinematic = False
*| + SphereCollider, isTrigger = False
| 
---- Sight GO 
|    + Box Collider, Is Trigger = True 
|    + Script to alert AI can see player 
| 
---- Hitbox GO 
     + Box Collider, Is Trigger = False 
     + Script to alert AI Damage
*     + Rigidbody, isKinematic = True