NavAgent2D takes a very round about way to the target

Godot Version

4.7.2.Stable

Question

Hi,

I am trying to make a very simple, horde ai (think vampire survivors). I basically only need my agents to path around obstacles and then beeline towards the big tank.

This is the navmesh:

The polygon is baked from the tilmap data and sadly creates a very messy polygon, I normally would not care but I think it causes the issue I am having:

Nav agents will take long and roundabout ways, sometimes even THROUGH the target to walk up to it from the other side, I have never seen this happening while working with 3D navigation. This happens with any form of post processing, even when turned off, they seemingly decided that the shortest way is not the unobstructed direct line to the target but instead to walk all the way off screen to come at it from the opposite side.

This essentially breaks my game since it completely gets rid of the difficulty.

I am at wits end, I have tried a few different options, implementing avoidance didnt help either. I assume the agents use these polygon triangles to navigate so when it is an open area and it creates these long and thing polygons it seems to break, but I don’t know how it works under the hood. AStar shouldn’t create these sort of results.

I managed to figure out the issue, I will write it here in case anyone else runs into this problem.

Tilemaplayers have a nav mesh layer, I filled that out in order to be able to bake the polygon using the region, assuming that the navigation server would use this baked polygon. It does not. It uses the tilemap one which for some reason produces this strange behavior.

My workaround was to:

  • Remove the navigation layer from the tilemaplayer
  • Add in collision for the nav agents to replace the lost information about where agents shouldn’t go
  • Deleted the baked polygon
  • Drew a polygon using the navigation region’s draw tool
  • then I baked it again, this time using the newly added collision information

The polygon still looks kinda all over the place but it works now. This still feels like a bug, even if you are supposed to beable to use tilemaplayers without nav servers, the pathfinding on them just seems broken.