Why is this happening? 2D navigation

Godot Version

4.3

Question

***SOLVED
suggested method of changing agent_radius fixed it. I had to wait a while for it to apply.

okay, so i made some navigation regions with the editor(can’t believe I didn’t try this first) and the issue seems to be that there’s a gap between what I want to draw and what Godot actually draws.

see image:
https://imgur.com/a/QJVFZxN

I tried changing all the values I can to see what makes that gap go away, but I can’t find what’s causing it. Can anyone help?

== original question ==
I’m playing around with navigation stuff to learn about them. I can’t figure this one thing out.

this is the code snippet. It’s a sample code that’s straight copied from the official docs of NavigationPolygon page.

var navigation_region = NavigationRegion2D.new()
var new_navigation_mesh = NavigationPolygon.new()

var bounding_outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
new_navigation_mesh.add_outline(bounding_outline)
NavigationServer2D.bake_from_source_geometry_data(new_navigation_mesh, NavigationMeshSourceGeometryData2D.new());

navigation_region.navigation_polygon = navigation_polygon
add_child(navigation_region)

and this is the result: (imgur)

https://imgur.com/a/TxwJPWN

The top-left corner of the white background is the origin point (0, 0).

As you can see, the navigation layer does not start in (0, 0), although the vectors i gave it include the origin point.

All the nodes in the scene have their positions set to the origin.

Why is this happening and how can I fix it?

There are several possibilities why this happens. First the object you are adding the child to is not at (0,0). Second, when a navigation-polygon is baked it has a value called “agent_radius” which is basically a distance to the border points. if you want this to be 0 you have to set it specifically sine the default value is 10:

navigation_polygon.agent_radius = 0
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.