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

Collision levels on player and ghost are set on 3

games777 changed the title to PathFinding -Target is unreachable .

Ive been able to solve this myself

updated code

extends CharacterBody2D



@onready var nav_agent = $NavigationAgent2D

@onready var player = $"../CharacterBody2D"

const SPEED = 200

func _ready():
	nav_agent.set_target_position(player.get_position())

func _physics_process(delta):
	
	nav_agent.set_target_position(player.get_position())
	
	if nav_agent.is_target_reachable() and !nav_agent.is_target_reached():
		var next_location = nav_agent.get_next_path_position()
		var direction = self.global_position.direction_to(next_location)
		velocity = direction * SPEED
		
		move_and_slide()

the reason why me enemy wasnt following me was that I didnt set up NavigationRegion and Navigation obstacles. After I´ve done that all works as desired.