Solved: Issue with NavigationAgent2D

Godot Version

4.2.1 stable

Question

I have a weird problem: in my game i created an enemy who shoul follow the player with a navigationagent2d, this is the code:

func handle_movement():
	    $NavigationAgent2D.target_position = player.global_position
	    var direction = 
to_local($NavigationAgent2D.get_next_path_position()).normalized()
	    velocity = direction * speed

with a navigationagent2d node set in the enemy scene tree; my game is made of different rooms (top-down arpg), all in the same level scene (different positions), and if i put my enemy in the first room it works fine. When i put it in the second room he activates and instead of following the player it goes in a straight line and is stuck in a wall (in doing so the debug line of the navigation agent doesn’t show up). When analizing what he is using as end point of the path (with get_final_position) the y coordinate updates correctly as the player moves, but the x coordinate is stuck and very far.

The tilemap is correctly set up for navigation (the floor tiles do have a navigation layer which is the same of the navigation agent), and every room has a different tilemap layer (i know this is not its typical use, but i did so for gameplay reasons) but navigation is enabled in all of them.

Do you have any idea what’s happening here?

Solved: I didn’t know there were different RIDs for navigation on different layers

I’m facing the same problem, how did you solve this??

Every layer of a tilemap (and i think every tilemap as well) has got a different navigation RID: if you don’t set it up correctly, your enemy will try to reach you by passing through another room

Okay so how did you solve that problem?

I used the command .get_navigation_map() every time i set up an enemy using navigation

I was able to set up the RID for the character but how did you set it up for the tilemap?