NavigationRegion3D - unable to figure out how Enter Cost works [project link]

Godot Version

Project created on MacOS with 4.4 beta2 but tried it on 4.2 and i get the same result

Question

I’ve been trying to figure out how to work with Enter Cost of a NavigationRegion3D.

nav-demo

So i’ve built this simple project - we have two regions, outer in white and inner in black.

I want to have a high Enter cost for the inner one so that the agent will avoid it.

If you disable the inner one the nav agent respects that and will avoid it.
But if you change the Enter cost of inner region it will always enter it for paths where it makes sense (like crossing directly over it to get to the other side) even if you put ludicrously high values for Enter cost of inner region.

Github project

Enter enter cost value is a flat value that is added to the travel distance when the pathfinding compares the closest distance between the next polygon edges. Astar can be pretty determined to run into the direction of the target position polygon and does and early exist the moment it finds this target polygon, it will not search everything. So your result and success with using enter or travel cost very much depends on your polygon layout.

@smix8 I played with this some more.

I extended the AStar3D in GDScript, it loads the same NavRegions as the default NavServer, gets their polys, re-creates the grid and adds points to AStar.

In my custom implementation i’ve updated the AStar cost function to take into account Region’s enter cost and it works - the regions nav mesh is either taken into account or skip based on the conditions i set via the UI.

nav-demo-2

You can see that the gray balls represents the paths I get directly by querying NavigationServer3D.map_get_path, the brown one is from my custom implementation of AStar.

The area which is enclosed with 4 vertical white lines is the NavInner which has a default region enter cost of 20. And the default algo always decides to cross over it, while the custom AStar respects the cost.

You can then see me tweaking the cost and the enable value of the InnerNav region.