Navigation2D first point sometimes wrong

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Loop

Hi,

I’m having some trouble with a Navigation2D on a tilemap. I’ve attached a screenshot showing what I’m attempting. (green squares passable, red not).

The first thing that happens is both the enemy and the player snap to the center of the grid square they are in (the yellow dot). Then, I call the get_simple_path function on the Navigation2D for the bat to work its way to the player.

On screenshot 1 it’s mostly okay, but it stops short and never reaches the player.

On screenshot 2, the first thing it does it goes to the left, then goes right and follows the path as it should, stopping within range of the player. I’m not sure why it makes this initial move to the left, as there is no route in that direction. For a bit of context, this is the position of the bat after it has snapped to the center of it’s grid square:
(176, 16)

and this is the path it is generating following that:

[(160, 16), (192, 16), (208, 32), (208, 64), (208, 96), (192, 112), (160, 112), (144, 96), (128, 80), (96, 80)]

It’s the 160, 16 that makes no sense. I would have thought it should be going for 192, 16 first?

Hopefully this makes sense and someone can advise. I wondered if it had something to do with the snapping I’m doing in the ready function, but taking that out doesn’t seem to fix it.

Yellow - snap position, red - path