godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.87k stars 21k forks source link

3.5rc1 Navigation2D: Cutouts in NavigationPolygonInstance not recognized by pathfinding if done in code #61334

Closed goddommitdom closed 2 years ago

goddommitdom commented 2 years ago

Godot version

3.5.rc1.official [e86d840d4]

System information

Windows 10, GLES3

Issue description

I keep reading that the proper way to interface with NavigationAgent2D is to cut out the StaticBody2D collision polygons from the NavigationPolygonInstance navigation polygon; however, attempting to do so results in polygons being visually removed, but not being treated as removed by any pathfinding.

The triangle was cut into the NavigationPolygonInstance in-editor; the trapezoids were done via code. As you can see, only the triangle actually registers as a "no-walk zone" despite the cut-out areas visually being cut out, and the NavigationPolygonInstance being disabled and re-enabled to refresh.

The polygons that are cut-out in code are ignored both with NavigationAgent2D and with the older get_simple_path() method.

NavigationIssue

Steps to reproduce

Edit a NavigationPolygonInstance's navigation_polygon via code. Included is a MRP. I've included a bool in Player.gd to switch between using NavigationAgent2D and the older get_simple_path(); neither method recognizes the cutout areas done in code.

Minimal reproduction project

NavigationPolygon.zip

akien-mga commented 2 years ago

CC @smix8 @Scony

smix8 commented 2 years ago

Seems some of the more recent navigation fixes did not make it to the 3.5.RC1 in time. In most recent Godot 3.x build the navpoly updates the navigationmesh correctly and the MRP works without these issues.

Your custom navmesh cutout code works fine. I also tested with all collision objects disabled and the agent stays on the new cutout navmesh all the time.

Note that for your current MRP movement code to work in the most recent Godot 3.x build you need to enabled the "avoidance enabled" bool on the NavigationAgent2D that was recently added.

EDIT: Found it!

61149 pr is what fixes your issue.

goddommitdom commented 2 years ago

Thanks for the link, appreciated!

Calinou commented 2 years ago

Duplicate of https://github.com/godotengine/godot/issues/18669 (same cause). This will be resolved in 3.5rc2 which should be released in a few days' time.