I've been having some issues with the Navigation2D system while working on a tower-defence game.<br /><br />The setup is, I have a grid that I can place towers on, and the grid is covered by a large navigation polygon which is generated in GDScript through the add_outline() method of the NavigationPolygon resource. When a tower is placed, the same script is given the position, and a square representing the tower's grid position is placed on the navpoly in the same way which cuts out that square as being walkable. This works as intended for single towers inside the grid but breaks when a tower is placed next to another one, or placed along a wall of the grid.<br /><br />When I place a tower in the corners of the polygon (excluding the bottom right corner, I have no clue as to why) as well as place a tower on the diagonal of another I get the "double up on navpoly" error, but when I place along the edge (and the bottom right corner) or against another tower vertically/horizontally I get "convex partition failed!" printed to the console for that and any towers I try to place afterwards.<br /><br />Here's the block of code managing all of this, add_block() is what is called every time a tower is placed, taking a position along an array which is turned into a 2d coordinate. Apologies for the magic numbers I've just been trying to get this working first :P<br /><br />
<br />extends Navigation2D<br /><br />var nav_mesh<br /><br />func _ready():<br /> nav_mesh = get_node(&quot;NavigationPolygonInstance&quot;)<br /> # forgive me for i have sinned<br /> nav_mesh.get_navigation_polygon().add_outline(Vector2Array([Vector2(-512, -512), Vector2(512, -512), Vector2(512, 512), Vector2(-512, 512)]))<br /> nav_mesh.get_navigation_polygon().make_polygons_from_outlines()<br /><br />func add_block(position):<br /> var x = position % 16<br /> var y = floor(position / 16)<br /> <br /> var polygon = Vector2Array([Vector2((x - 8)
64, (y - 8) 64), Vector2((x - 7)
64, (y - 8) 64), Vector2((x - 7)
64, (y - 7) 64), Vector2((x - 8)
64, (y - 7) 64)])<br /> <br /> nav_mesh.get_navigation_polygon().add_outline(polygon)<br /> nav_mesh.get_navigation_polygon().make_polygons_from_outlines()<br /> <br /> print(nav_mesh.get_navigation_polygon().get_vertices().size())
<br /><br />Any help would be appreciated, before I just go and implement A*.