Godot Version
4.2.2
Question
I managed to set up my navigationPolygon and want to run a NavigationAgent2D
on it. I set it up as a CharacterBody2D and the logic for the node is as such:
extends CharacterBody2D
@onready var navigation_agent = $NavigationAgent2D
var SPEED: float = 1
var target_position: Vector2
var move_ready: bool = false
func _ready():
var start_position = Vector2(20,20)
position = start_position
target_position = Vector2(100,100)
set_target_position(target_position)
NavigationServer2D.map_changed.connect(warn) ### Wait for the map update so I won't get errors
func _physics_process(delta):
if move_ready:
if position.distance_to(target_position) > 0.5:
var current_location = global_transform.origin
var next_location = navigation_agent.get_next_path_position()
print(navigation_agent.is_target_reachable())
var new_velocity = (next_location - current_location).normalized() * SPEED
velocity = new_velocity
move_and_slide()
func warn(_data):
move_ready = true
func set_target_position(target_pos: Vector2):
navigation_agent.set_target_position(target_pos)
However, the print(navigation_agent.is_target_reachable())
command always returns false
The game map uses a TileMap, but it doesn’t have any navigation layer set.
All I use is a NavigationRegion2D
which after baking shows the entire map as accessible.
What could be the issue here?