# How to do collision detection in Unity between Character Controller, Rigidbody Collider and a NavmeshAgent?

I would like to know more about how collision detection works in Unity especially when character controllers and NavmeshAgents get involved.

For example, how can I detect collision between NavmeshAgent and a CharacterController? I have added a sphere collider to my NavmeshAgent, but it doesn't seem to detect a collision unless I set it to "IsTrigger". I have tried OnCollisionEnter(), OnControllerColliderHit() and OnTriggerEnter(). OnTriggerEnter() seems to be the only one that works and only when I enable "IsTrigger".

How come the other two don't work? Shouldn't they? What if I didn't want to make the collider a trigger?

• Presumably you started by reviewing the documentation on this matter (in particular, the Collision Action Matrix at the bottom)? – DMGregory Jun 10 '20 at 18:30
• @DMGregory Yes I came across that, but it doesn't explain how things work when navmeshagents or character controllers get involved. – xcrypt Jun 10 '20 at 18:31
• If you want collision with a NavMeshAgent, it needs a kinematic Rigidbody, as explained in the docs. The CharacterController's OnControllerColliderHit is also documented. – DMGregory Jun 10 '20 at 18:39
• @DMGregory I have read those couple times, but do I always need to use OnControllerColliderHit when working with character controller? And why can I not detect a collision between a non-trigger kinematic rigidbody collider (in the NavMeshAgent's case) and a Character controller? This doesn't seem so transparent in the documentation – xcrypt Jun 10 '20 at 18:50
• This is explained in an existing answer here - OnCollisionEnter is part of the physics collision response. Kinematic bodies and CharacterControllers don't experience a physics collision response - they don't bounce off an obstacle unless your code tells them to. So the OnCollisionEnter method is not called unless at least one of the participants has a dynamic rigidbody (as shown in the matrix), because that's the only case that experiences a physics collision response. – DMGregory Jun 10 '20 at 18:55