Enemy reaches players position then stops

Godot Version

June 23 - 4.2.2


I have an enemy that is supposed to simply move towards the player. It does move to the player’s spawn position, but then it stops. I think my code is correct and that the problem may be something else.

Here’s the code for the enemy:

extends CharacterBody3D

var player = null

const SPEED = 4.0

@export var player_path : NodePath

@onready var nav_agent = $NavigationAgent3D

Called when the node enters the scene tree for the first time.

func _ready():
player = get_node(player_path)

Called every frame. ‘delta’ is the elapsed time since the previous frame.

func _process(_delta):
# Enemy movement towards player
var current_location = global_transform.origin
var next_nav_point = nav_agent.get_next_path_position()

player = get_node(player_path)
velocity = Vector3.ZERO
velocity = (next_nav_point - current_location).normalized() * SPEED
1 Like

Nvm I solved it. I changed the player path to the players characterBody3d and it works now.