Why Do Raycasts Ignore NavMesh Agents

I built a simple game using Unity’s built in NavMesh Agent AI system.

My player has a laser that uses a raycast to apply a force to the enemy to not it back. This works… for the first couple seconds of the game. Then, it is as if the NavMesh Agent gets “locked” into movement and is no longer effected by the raycast. I have found a few (very small number) other questions on UA, but none have answers that apply to my situation.

Is this a bug in Unity?

Or Am I missing some aspect of NavMesh Agents.

I believe I have a solution to the problem.

I believe the problem occurs when you have both a Navmesh Agent on the object as well as a Rigidbody. Remove the Rigidbody and it should work fine.

I realize this is years after the fact, but I was having this same problem.

The only thing that was fixing it was what @Meatloaf4 said about removing the Rigidbody, but then that made the navigation wonky. So what I did that seemed to fix it was I changed the Collision Detection on the Rigidbody component from Discrete, to Continuous instead.

That seemed to fix it.

Hey, I know this is a really old post. But I had this issue and fixed it by setting the Rigidbody as Kinematic.

I was trying to get a ragdoll to work so I used:

foreach( Rigidbody rigidbody in GetComponentsInChildren<Rigidbody>() )
    rigidbody.isKinematic = true;

Try replacing the BoxCollider on your object with a MeshCollider.
This is probably due to mesh sort order; RaycastAll() will also work.

Changing from Discrete to Continuous does not solve the issue. Rigidbody still needs to be removed.

I had the same problem. Changing Interpolate option to Interpolate and setting Collision Detection to Continuous Dynamic solved my mine.

The raycast works fine, the problem is that you have two entities that try to take control of your gameObject position - the dynamic rigidbody and the navMeshAgent. They both have their internal positions and try to synchronize it with transform. It’s quite possible that when both are present, they get desynced and their relative positions change. Just go to the scene view when this error manifests and see if the navMeshAgent, rigidbody+collider and the visible mesh (or whatever you are using) are in the same position or not.

This makes sense - the NavMeshAgent tries to interpolate the position on a path on a navMesh, the rigidbody has its own opinion on where the object should be, and they are incompatible. So you must pick one of them to “own” the position. (Or, you could disable position updates of both and handle it entirely in your script)
I’d say that if you want to have a rigidbody behaviour, then you want to keep the rigidbody behaviour… and disable the navmesh position update. You can actually disable the position update on the navMeshAgent, but it will still internally move towards the target - it just won’t move the gameObject. Now I am not sure what’s the best way to handle this, but one thing I’d suggest is to set the navMeshAgent velocity and acceleration to zero, disable the position update, then every FixedUpdate tell the navMesh your new position from the physics, and finally, take the navMeshAgent’s desired direction that comes from its path and calculate forces to move your rigidbody that way.
If there’s some built-in solution to this conflict, anyone pls enlighten me. But I am not aware of it.