- Home /
Do your NavMeshAgents choose different paths in the editor?
Hey folks...I'm having a strange problem that occurs periodically that I can't really seem to pin down.
I'm using Unity Pro's navigation mesh and agent to make my scene walkable.
I have a "maze" of roads that fan out from one of two peripheral locations (the red side of the map and the blue side of the map). Those roads lead to intersection points where targets are and ultimately they lead to the other side of the map.
Part of my game mechanic is that players pick a road to traverse to try to reach the other side. The agents stop at any intersection where a target lives and do what they can to destroy it before moving on to the opposing team's side of the map.
The game is played asynchronously, so I record what choices the player made on the server and replay them when the opponent logs in to the game. 9 times out of 10 this works fine and the replayed navigation choices are the same as when the player originally made their move. But often (and mostly in the Unity Editor) the agent chooses a different path and will end up getting stuck. In fact, the agent will often go down a dead end path where the navigation mesh is broken and it will pin itself in a corner.
This leads me to 2 questions:
Why would the agent make a different choice in the editor than it makes in the live game?
Why would the agent choose to go down a non-connecting dead end path with no hope of ever reaching its goal?
I believe Unity's navigation system allows me to put a cost on a road...but I don't really think that's what I want to do. I don't want to force a road choice...or make one road preferential over the other. I want the AI to choose the shortest path. But it seems as though there is some flaw in the logic that causes it to play differently.
I currently have a saved game on my server wherein if I load the game on my iPad or in the Web Player, it fairly consistently chooses the right path (although not 100% of the time), but when I run the game in the editor it fairly consistently chooses the wrong path and the bot gets stuck.
Are there any parameters of the agent that make the navigation decision "fuzzy" that I can tweak to eliminate the fuzziness?
What I've been doing to manage the problem is creating "breadcrumbs" along the path that I want the AI to follow. This urges them down the path I want them to take in shorter increments, but it also requires me to manage these breadcrumbs which can be painful when I change the scene geometry or add and remove new targets. Also, it doesn't really solve the problem...sometimes the bots get stuck en route to the next breadcrumb. :-/
Thanks in advance for any guidance.
So...another wrinkle for this question (which seems to be stumping the community as well as it's stumped me)...I have added a feature to my game wherein when the player highlights a spawn point, a marker gets created and follows the path that the agents spawned from that location will take to reach their destination.
The problem is this...when the marker gets spawned...it immediately takes a "wrong turn" choosing a different path than the actual agents that are spawned from that location will take. I've checked all the properties of the nav mesh agent to ensure that its radius is not so big as to create an "obstruction" on the path. I've set its parameters to be the same as the actual game objects that get spawned from that location, and still, 100% of the time, it chooses a different path.
Does anyone know of a way to make the navigation/pathfinding more deter$$anonymous$$istic?