Search code examples
c#unity-game-enginecollision-detection

OnTriggerEnter() not called


I have a player (sphere) and 4 enemies (capsules). All enemies have a character controller added. They also all have a child GameObject, which has a RigidBody (no mass, no gravity) and a Box Collider attached. The Box Collider is large enough so you can see the sphere model inside of the box, even with a little space in between.

The player also has a character controller, but no RigidBody. It does have a sphere attached with a mesh collider.

All of the enemies have the IsTrigger box checked. Why don't they call the OnTriggerEnter() function? Note that when enemies collide, OnTriggerEnter() is called. But it doesn't work on the player.


Solution

  • Is the sphere a child GameObject to the player, or is it the GameObject itself? You might want to check where the script is attached. If the script is attached to the player but the collider is on a child GameObject, that isn't quite going to work. Collider and script need to be on the same GameObject.