- Edited
I just started using Navigation nodes and have the following setup:
Navigation region in main scene:
NavigationAgent2D that is represented by an enemy scene:
NavigationObstacle2D, in this case a wall:
And the code in script attached to enemy AI child node:
func actor_setup():
await get_tree().physics_frame
func _ready():
call_deferred("actor_setup")
set_state(State.PATROL)
navigation_agent.path_desired_distance = 4.0
navigation_agent.target_desired_distance = 4.0
navigation_agent.avoidance_enabled = true
func _physics_process(delta):
if navigation_agent.is_navigation_finished():
maneuver_location_reached = true
else:
var next_move_position = navigation_agent.get_next_path_position() - actor.global_position
actor_velocity = next_move_position.normalized() * movement_speed
actor.velocity = actor_velocity
actor.move_and_slide()
The end result is that enemy NavigationAgent2D does not take wall cover into consideration and goes around it. Instead it keeps trying to reach navigation target position. You can see on screenshot that the path is intersected by a yellow wall, so it should go around it (the enemy is the small green sprite stuck to the yellow wall...ignore the red raycast pointing left....):
What am I missing? Why is the obstacles not taken into consideration when navigation_agent is getting its next path point?