Godot Version
v4.2.2

SOLUTION THAT WORKED IN MY CASE:
I have increased the path desired distance and now it is working, I will not lie, I did not really get the point well why it works now, but you can try it out if you have the same problem

Short description:
Hi guys! Well I really need some help, my script return the wrong position in the function get_next_path_position(), so everything goes wrong : P
By the wrong position I mean that I get the position of navigation agent's parent, according to the docs it happens because the "Agent does not have a navigation path".
So the enemy just does not move D:

DOCS

If the agent does not have a navigation path, it will return the position of the agent's parent.

Code part:

# Hunting
@onready var nav_agent = $NavigationAgent3D

var SPEED = 10.0

# It is being updated through the world script
func update_target_location(target_location):
	nav_agent.target_position = target_location

func _on_navigation_agent_3d_target_reached():
	print("Dead")


func _physics_process(delta):
	# Monster's hunting for the player.
	if active == true:
		var current_location = self.global_position
		var next_location = nav_agent.get_next_path_position()
		var new_velocity = (next_location - current_location).normalized() * SPEED
		
		print(nav_agent.is_target_reachable()) # Returns true
		
		velocity = new_velocity
		move_and_slide()

This works:

  1. navigation_agent.target_position — when used with print(), prints position of the PLAYER (so the navigation_agent.set_target_position() works)
  2. I have checked all the navigation layers and they match.
  3. The baked map seems to be fine.

This does not:

`var next_location = nav_agent.get_next_path_position()
		var new_velocity = (next_location - current_location).normalized() * SPEED`

I really need a little help in here, basically my enemy just does not move at and I checked the others topics about this problem but their solutions seem not to be working so I would be really grateful, if someone would help me out 😃!

Additional helpful info:
A picture of the navigation path with the debug (The navigation path seems to be structured the right way)

A picture of the NavigationAgent’s settings

    Seva sounds like the target is not set?

    my code that works:
    enemy.gd

    func _physics_process(delta: float) -> void:
    	if player_node != null:
    		if player_node.enemy_follow:
    			follow_target = true
    		else:
    			follow_target = false
    		
    	if target is Player and follow_target: 
    		navigation_agent_3d.target_position = target.global_position
    		var direction = (navigation_agent_3d.get_next_path_position() - global_position).normalized()
    		if direction and follow_target:
    			var new_velocity =direction * SPEED
    			velocity.x = move_toward(velocity.x, new_velocity.x, 0.25)
    			velocity.z = move_toward(velocity.z, new_velocity.z, 0.25)
    			#velocity.x = direction.x * SPEED
    			#velocity.z = direction.z * SPEED
    			rotation.y=lerp_angle(rotation.y,atan2(-velocity.x,-velocity.z),0.2)
    
    	else:
    		velocity.x = move_toward(velocity.x, 0, SPEED)
    		velocity.z = move_toward(velocity.z, 0, SPEED)
    • Seva replied to this.

      kuligs2 I didn't mention that it is being updated in the world script, my bad, thanks for the code though, I will try to implement it in some places and see what happens : D