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?
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 theOnCollisionEnter
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. \$\endgroup\$ – DMGregory♦ Jun 10 '20 at 18:55