Godot Version
GoDot 4.4.1 (.NET)
Situation
Hey guys,
I have very exhausting problems with navigation for a week now. I am working on a top-down 2D game. I have a player, user controlled, and an enemy, a NPC controlled by NavigationAgend2D.
If you need more details, please let me know.
Problem 1 - Detour
So the enemy (controlled by navigation agent) should go on the shortest way to my player. Sometimes everything is working fine, but sometimes the enemy’s path is going away from the player then he turns about 300° degrees and then going to player, still not on perfect way. Sometimes this path is going through navigation polygon holes.
Problem 2 - Baking error
I have 2 relevant TileMapLayers, the “Ground” layer and “Barrier”.
The tiles in Ground owns navigation polygons and the TileSet have the “Navigation Layer” 1.
The tiles in Barrier owns only collision and no navigation polygons.
The NavigationPolygon’s “Source Geometry Mode” of the NavigationRegion2D is “Group Explicit”. Only Ground and Barrier are assigned to this group. But when baking, I always get this error:
E 0:00:00:954 _build_step_find_edge_connection_pairs: Navigation map synchronization error. Attempted to merge a navigation mesh polygon edge with another already-merged edge. This is usually caused by crossing edges, overlapping polygons, or a mismatch of the NavigationMesh / NavigationPolygon baked 'cell_size' and navigation map 'cell_size'. If you're certain none of above is the case, change 'navigation/3d/merge_rasterizer_cell_scale' to 0.001.
What I tried
- Change the merge rasterizer cell scale to 0.001. => baking error still there
- Removed Barrier from navigation group => no baking error but path always through barriers, detour same as before
- Some more, I forgotten
Code
Baking:
public override void _Ready() {
navRegion = GetNode<NavigationRegion2D>("Map/NavigationRegion");
navRegion.BakeNavigationPolygon();
}