- Edited
I am new in Godot, I want my enemy to follow my player but it won´t move. After some debugging I found out that the problem is that "target is unreachable" which I dont understand why.
This is my map it´s made out of sprites and collisions.
This is what my main character is made of
and the ghost that should haunt it
The ghost should follow the player but it does not, instead it just sits there, it´s because print("not reachable") is reached I presume but why?
my code on ghost:
extends CharacterBody2D
var SPEED = 50
@export var player: Node2D
@onready var nav_agent = $NavigationAgent2D
func _ready():
# Make sure to not await during _ready.
call_deferred("actor_setup")
func actor_setup():
await get_tree().physics_frame
nav_agent.target_position = player.global_position
func _physics_process(_delta: float):
if nav_agent.is_navigation_finished():
print("Navigation finished")
return
if nav_agent.is_target_reachable():
print("TArget is reachable")
else:
print("not reachable")
var dir = to_local(nav_agent.get_next_path_position()).normalized()
velocity = dir * SPEED
move_and_slide()
func _on_timer_timeout():
nav_agent.target_position = player.global_position