I am trying to get pathfinding working on a tile-based game. Right now I have two TileMapLayers, one for the floor, and one for the walls. The wall tiles are physics tiles that character bodies collide with. These TileMapLayers are then connected to a NavigationRegion2D.
Currently I am just trying to get my NavigationAgent2D to pathfind to a node that has a static, unchanging position. It seems to handle wall avoidance just fine, but once it gets near the target node the path goes off the rails and takes a very inefficient route.
My first thought was that it had something to do with the agent’s target desired distance, but modifying that hasn’t made a difference. I’m not quite sure what the agent is trying to do here.
Here is a screenshot of the path it takes (one example, other patterns of walls lead to similar results):
Ah, this is correct, I had forgot about this behavior.
I suppose my question would then be, is there a way to prevent the mesh from generating paths that cause this? Ideally I would like to retain path points being centered on tiles, as when I set postprocessing to corridorfunnel it causes the agent to get uncomfortably close to the walls and can lead to it getting stuck. All I can think of is just placing more walls to add more points to the mesh.
Looks like increasing the agent radius enough to force it to path closer to the middle of floor tiles is as close as I can get it. Not sure if the most elegant solution but seems to be working well enough. Thanks!
I dont understand why you are trying to force the path in the middle when using a navmesh. The point of a navmesh is that the entire surface is usable by the agent and is as efficiently partitioned with as few polygons as possible.
If you need grid forced cells the AStarGrid2D would be a far better option.
Sorry, maybe I worded that poorly, not trying to get it exactly middle, just trying to make sure it doesn’t ride walls as much and get stuck on things. But I will look into AStarGrid2D, thank you.