Godot Version
4.2.1 Stable
Question
My navigation agent cannot generate the path, and I cannot figure out how to get around it.
I’ve tried telling the navigation agent to wait before initializing it, I have set up the navigation layer, the agent knows where it’s starting from and where it’s supposed to go, but the path array ends up being empty.
Full description wiht pictures:
https://www.reddit.com/r/godot/comments/1eafvuk/cant_get_navigation_agent_to_build_the_path/
Code (the required parts):
extends CharacterBody2D
u/export var target : Area2D = null
@onready var navigation_agent_2d = $NavigationAgent2D
var movespeed = 50
func _ready():
set_color()
call_deferred(“set_target”)
func set_target():
await get_tree().physics_frame
if target:
navigation_agent_2d.target_position = target.global_position
func _physics_process(_delta):
if target:
navigation_agent_2d.target_position = target.global_position
await get_tree().physics_frame
var current_agent_position = global_position
var next_path_position = navigation_agent_2d.get_next_path_position()
velocity = current_agent_position.direction_to(next_path_position) * movespeed
if navigation_agent_2d.is_navigation_finished():
return
print(current_agent_position)
print(next_path_position)
print(navigation_agent_2d.target_position)
move_and_slide()
Blockquote