get_next_path_position() always returns the enemy’s current position.
I’ve read some other posts and I understood this should be because I haven’t set a navigation layer on my tilemap but even after I added it, and painted the right tiles with it, the navigation agent still refuses to get the next position.
This is my code for navigation in the Enemy class:
var current_pos: Vector2 = global_position
var next_pos: Vector2 = navig_agent.get_next_path_position()
var new_velocity: Vector2 = current_pos.direction_to(next_pos) * speed
if navig_agent.avoidance_enabled:
navig_agent.set_velocity(new_velocity)
else:
_on_navigation_agent_2d_velocity_computed(new_velocity)
These are the settings on NavigationAgent2D and TileMap respectively:
IMO, this is a bug. I’ve spent a whole day on this, so far.
✓ get_current_navigation_path() returns an array of points - we have found a path
✓ is_navigation_finished() returns false - we haven’t arrived
✓ character velocity is non-zero - character does move. it just gets stuck on a waypoint
✓ distance to get_next_path_position() is smaller than nav_path_desired_distance, so we should advance to next waypoint.
nav_path_desired_distanceis 0.5
𐄂get_next_path_position()keeps returning the same position
Still having this issue in 4.6.2. Not sure about how to fix. Turning on debug on the navigation agent shows the correct path, but getting the next point on the path with code somehow gets the target position instead of the next point instead.
Edit: I lowered the Path Desired Distance and Target Desired Distance a lot and it started working.