I’m following a tutorial on state machines with navigation. However, the target position shown in print() is always 0,0, and as a result, all my characters move towards global when starting the game. I’m unsure of what went wrong as i have followed the tutorial code exactly, yet I’m not getting a randomised target_position as shown in the tutorial.
There’s been a similartopic posted by someone following the exact same tutorial, but i’m pretty sure set_movement_target() has been called in my case, seeing as the print statement is working?
They seem to? navigation_agent_2d.navigation_layers returns 1, which is correct, and get_navigation_map() returns RID(1288490188800), which is probably correct…?
set_movement_target()" works just fine if i put the function in
func _on_physics_process(_delta : float) -> void:
if navigation_agent_2d.is_navigation_finished():
set_movement_target()
return
var target_position: Vector2 = navigation_agent_2d.get_next_path_position()
var target_direction: Vector2 = character.global_position.direction_to(target_position)
character.velocity = target_direction * stats.speed
character.move_and_slide()
print(target_position)
the npc is able to navigate normally after heading to 0,0 after starting the game. Im assuming that there’s something wrong with it being called initially, but at the same time, the values for navigation_agent_2d.get_navigation_map(), navigation_agent_2d.navigation_layers are already there, so there’s no reason for it to be not executed properly…
I have an error: upon starting, all the chickens walk towards the same point and then move randomly.
Then he followed up with:
I finally fixed the issue: I wasn’t allowing the area to load first. The solution is to put await get_tree().physics_frame in the setup and set a random position just above.