I'm currently attempting to use collision detection for target selection (auto attacking). I have two objects (i.e. a player and a tower), each game object has an object hierarchy as such:
Here, the object has a:
Based on this I have set each child object to have a sphere collider and set to a layer corresponding to the type of sphere it is. Below is the physics collision table currently being used. I only want the HitBox layer and Target Layers to be interacting with eachother.
Despite my best efforts, when running the game and having the player walk back and forth through the spheres, OnTriggerEnter()
is never called. This method is located in the player and towers classes which are on the parent game object. Currently I have no rigidbody on either the player or the tower, but do have triggers on both of the both the player's and tower's hit spheres to trigger each others OnTriggerEnter()
.
So far I have tried:
Lastly, Here is an image of the two objects colliding, each within each others spheres but not calling each other's OnTriggerEnter()
. The Cylinder outline is from the NavMeshAgent Controller which I have also tried to remove and test with but also to no avail. :(
TL;DR: Trying to do compound collision detection on multiple game objects to no avail.
The answer is actually buried in your question.
From the Unity docs found here:
Note: Both GameObjects must contain a Collider component. One must have Collider.isTrigger enabled, and contain a Rigidbody. If both GameObjects have Collider.isTrigger enabled, no collision happens. The same applies when both GameObjects do not have a Rigidbody component.
But per your post:
Currently I have no rigidbody on either the player or the tower, but do have triggers on both of the both the player's and tower's hit spheres to trigger each others OnTriggerEnter().
So, the quickest fix sounds like it would be to add a Rigidbody to your Towers. You could also add one to your player, but make sure your collision matrix excludes the player from the encircling trigger sphere colliders.
And lastly, as per the docs, a trigger won't be triggered by another trigger.
Fix those issues, and you should be seeing the behaviour you expect.