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:
- navigation_agent.target_position — when used with print(), prints position of the PLAYER (so the navigation_agent.set_target_position() works)
- I have checked all the navigation layers and they match.
- 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!