- Home /
Why Do Raycasts Ignore NavMesh Agents
I built a simple game using Unity's built in NavMesh Ageant 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 to am experiencing this issue and have yet to find a solution. It seems that my raycast collides for some arbitrary amount of seconds and then stops working. I'm currently using Physics.Raycast() but I have also tested with a sphere cast.
$$anonymous$$y code was set up as follows
Physics.Raycast(mainPosition, dirOne, out hitOne);
Please help!
Answer by Meatloaf4 · Mar 11, 2014 at 08:37 AM
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 will try this. I have a temporary fix right now. Triggers still work fine for nav$$anonymous$$esh agents so I have been just using triggers, but i will try your solution.
$$anonymous$$eatlof you just saved me a lot of nerves and time :)
Answer by Nubaa · Jan 10, 2019 at 03:32 AM
I realize this is years after the fact, but I was having this same problem. The only thing that was fixing it was what Meatlof4 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.
Answer by doug__ · Feb 15, 2015 at 01:58 PM
Try replacing the BoxCollider on your object with a MeshCollider.
This is probably due to mesh sort order; RaycastAll() will also work.
Answer by abhishekm942 · Jan 01, 2021 at 10:43 PM
Changing from discrete to continuous does not solve the issue. Rigidbody still needs to be removed.
Your answer
Follow this Question
Related Questions
Can't get a laser working properly. 2 Answers
Player's last location as a Transform 1 Answer
Why are raycasts so unreliable? 2 Answers
My Raycast dont hit. 3 Answers
Collider Vision AI question. Solved! 0 Answers