NavigationAgent2D getting stuck at corners

Godot Version

4.4.1

Question

Hey there! I want to implement a system where enemies use path finding to get to their target position. The navigation region is defined using tiles (see attachments)

I have a problem where the enemies get stuck at corners. I’ve tried to adjust the parameters of the NavigationAgend2D to no effect.

How can I fix this behaviour? I don’t want to adjust the site of the painted navigation rect (see attachments) because then I’d have the same issue when working with StaticBodies outside of the TileMapLayer (I think)

CleanShot 2025-04-15 at 18.08.49

extends EnemyState

@export var max_speed := 200

var should_move: bool

func _enter() -> void:
	GameEvents.set_navigation_target.connect(_on_game_events_set_navigation_target)
	get_actor().navigation_agent.target_reached.connect(_on_actor_navigation_agent_target_reached)
	get_actor().navigation_agent.velocity_computed.connect(_on_actor_navigation_agent_velocity_computed)
	get_actor().navigation_agent.max_speed = max_speed


func _exit() -> void:
	GameEvents.set_navigation_target.disconnect(_on_game_events_set_navigation_target)
	get_actor().navigation_agent.target_reached.disconnect(_on_actor_navigation_agent_target_reached)
	get_actor().navigation_agent.velocity_computeddis.connect(_on_actor_navigation_agent_velocity_computed)


func _physics_process(delta: float) -> void:
	if not should_move: 
		return
	
	var target_dir := get_actor().global_position.direction_to(get_actor().navigation_agent.get_next_path_position())
	get_actor().navigation_agent.velocity = target_dir * max_speed


func _on_game_events_set_navigation_target(target: Vector2) -> void:
	get_actor().navigation_agent.target_position = target
	should_move = true


func _on_actor_navigation_agent_target_reached() -> void:
	should_move = false


func _on_actor_navigation_agent_velocity_computed(p_safe_velocity: Vector2) -> void:
	get_actor().velocity = p_safe_velocity
	get_actor().move_and_slide()