Questions about 2d Navigation

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

Few things with Godot built in 2d navigation.

  1. They keep getting stuck on other units going to the same place than wont move to a new position until they reach first their position.
  2. they seem to take a weird path/no optimal I made sure my navigation 2d was not the problem they are well within it

my code:

func _ready():
animation_player.play(“walking”)
Destination = WorldPOS.castle_position
Master.position = Vector2(1200, 300)
path = Nav_poly.get_simple_path(global_position, Nav.soldier_des, false)

func _physics_process(delta):

if click == true:
	crossair.global_position = touch_pos

if path.size() > 0:
	move_to_target()

func move_to_target():
if global_position.distance_to(path[0]) < threshold:
	path.remove(0)
else:
	var direction = global_position.direction_to(path[0])
	velocity = direction * SPEED
	velocity = move_and_slide(velocity)