[SOLVED] NavigationAgent3d.get_next_path_position() is not working

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 :D!

Try turning on debug on the NavigationAgent3D, it will show you the whole path, and will help you figure out if it generates a valid path at all.

What settings do you have on you NavigationAgent3D? There’s a few things that might go wrong there,

Hi! Thanks for answering, if these will help you:
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

Start by increasing Path Desired Distance by a lot just to see if that changes anything.

Make sure the NavigationAgent is located near the path, basically on the ground in your case. If it’s on the center of the character for instance, then it might just be further than 1m from the first path point (which usually is where the NavigationAgent starts).

It worked! I have increased the path desired distance and it seems that the problem you described, well was the actual problem, so thanks!:smiley:

1 Like