- Home /
Problem with AI and pathfinding.
Hi, I have a problem with my AI. I use unity's navmesh agent solution to order my AI enemies to go to the player
navMeshAgent.SetDestination(target.position);
but when there are other agents surrounding the player (i.e. the direct path is obstructed by other agents) the enemy freaks out, changing direction every frame. The video below describes my problem better: https://www.youtube.com/watch?v=NV6gVsYuooo I should note that my AI agents behave fine when there are only few of them and they do not surround the player.
Any help much appreciated.
Answer by Ziuber · Apr 02, 2017 at 04:07 AM
Hi, I ended up using Navmeshagent.path.corners[1]
to point my sprite in the direction of the target. The agents still move like on the video but their sprites don't change so rapidly so it's much better this way.
Answer by Lahzar · Nov 26, 2016 at 08:24 PM
The target.position is the players position, right?
So essentially you're telling every single AI to go to the players position. Which is already occupied by the player.
You can easily get around this by telling your AI to stop, say 2 units from the player or something, but you still end up with this problem.
Just because you use the same navmesh for every AI doesn't mean they are aware of eachother. Essentially they are all trying to stand in the same place, but are all blocked by, or pushed by eachother. As you have more AI trying to get to the player, you're more likely to have AI trying to stand in the same spot.
Your answer
Follow this Question
Related Questions
Find the closest point of an Invalid or Partial path 0 Answers
NavMesh Update Path 0 Answers
how do I add abilities(Scripts/GameObjects) to my path finding agent 1 Answer
Artificial intelligence - Find way through changing path 2 Answers
How to RayCast a triangular field of view for my autonomous moving agent 4 Answers