Help with Enemy Path finding

Godot Version (godot ver 4.2)

@onready var nav_agent := $NavigationAgent2D as NavigationAgent2D

##functions-----------------------------------------------
func makepath() ->void:
nav_agent.target_posistion = player.global_position

##built in functions -----------------------------------------------

func _ready():
var player = get_tree().get_nodes_in_group(“Player”)
print (player)

func _physics_process(_delta : float) → void:
direction = to_local(nav_agent.get_next_path_position()).normalized()

velocity = direction * speed
move_and_slide()

##called functions -----------------------------------------------

func _on_timer_timeout():
makepath()

Question

Im trying to do pathfinding for my enemies in my game but when i run this the enemy just doesnt move- no error appears. Im trying to figure it out but I cant

You should set the navigationAgent’s velocity by calling function set_velocity(velocity) on it. Like this:

nav_velocity = direction * speed
nav_agent.set_velocity(nav_velocity)

And also you mistyped here nav_agent.target_posistion .
This should help you.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.