How to detect a collision between NavmeshAgent and a CharacterController? Have added a sphere collider to my NavmeshAgent, but it doesn’t seem to detect a collision unless set to “IsTrigger”. Have tried OnCollisionEnter(), OnControllerColliderHit(), and OnTriggerEnter(). OnTriggerEnter() seems to be the only one that works and only when I enable “IsTrigger”.
The solution to the problem
The following conclusions are all collisions that aren’t character controllers are explained in the unity documentation.
When a character controller gets involved, you can still use the other methods as well (OnCollisionEnter() and OnTriggerEnter()), provided the other collider suits the conditions (non-kinematic attached rigidbody or an IsTrigger Collider, respectively).
To detect collision between two charactercontrollers, or between a charactercontroller and a rigidbody, you can also use OnControllerColliderHit(), on condition that you are using the intrinsic Move() method.
To detect collisions between two kinematic rigidbodies, you need to enable “IsTrigger” on one of the colliders. If in this case you still want the kinematic rigidbody to push around other objects, you need to add a second collider with “IsTrigger” set to false. This is also how you should detect collision with navmeshagents since they don’t function with non-kinematic rigidbodies.
I hope it helped somebody else who runs into similar issues. If you’re interested in what I’m up to, please check out my other articles. Happy coding!
Also read: SetDestination can only be called on an active agent that is on a NavMesh
References:
https://gamedev.stackexchange.com/questions/183405/how-to-do-collision-detection-in-unity-between-character-controller-rigidbody-c
Ambiz Education Search: