How to make navagent avoid corners?

Godot Version

4.5.1 stable

Question

I feel like there's a way to make it avoid corners or at least keep its distance somewhat, but so far all I've found is the "radius" property under avoidance, and even with avoidance checked it doesn't affect it. (I also think avoidance is moreso for obstacles rather than navigating the navregion)

As you can see, the nav-agent node directs it straight to the corner

and this is my code

if in_pursuit:
			nav_agent.target_position = Player.Main.global_position
			var direction:Vector2 = (nav_agent.get_next_path_position() - global_position).normalized()
			velocity = direction * SPEED
			move_and_slide()

I forgot to include the navigation region.

I have discovered apparently that kind of flexibility is only on properly baked navigation regions, so you don’t want to use the tilemap’s navigation Navigation on a procedurally generated TileMap with obstacles
Baking a navigation allowed me to set a proper radius

Inset the nav polygon when baking. If you’re using per tile navigation polygons you’ll need to create alternative tiles with adjusted polygons for edges and corners

1 Like

Do you have a visual example of this? I’m using the tilemaplayer’s navigation.

It’s trivial, just move the nav box edge away from tile edge towards the center. Do an alternative tile for each of 4 edges and for each of 4 corners. Corners would require moving 2 edges. You’ll need to manually place adequate alternative tiles onto the map or use tilemap’s automatic tiling if it fits your setup.

1 Like

Thanks. That does seem to work, though it will require more complex tile setup(and figuring out which tiles are which on this tileset I bought, when before I was just using a single floor tile), compared to just using a navigationregion2d and it being able to bake with the agent radius accounted for, so I’m probably going to try going with navigationregion2d’s method, once I figure out why the navigationregion2d has completely broken my nodes.

Quick correction: Nodes were not broken, they were just tool scripts with errors suddenly going off that turned out to be unrelated, and i forgot to put navigationregion2d above the other sprites so that it wouldn’t render on top of it :slight_smile:

1 Like