RTS Raycast units avoidance

Godot Version

4.3

Question

RTS Raycast units avoidance
Hello! I am working at RTS game and get a trouble, when units move to target to attack they can stuck among themselves. I tried resolve this by Raysact system but this work strange.

func move_to(point: Vector2):
	self.status = 'move'
	if(self.nav.is_navigation_finished()):
		self.status = null
		return
	self.nav.target_position = point
	#print(self.nav.get_simple_path())
	var prev_position = self.get_global_position()
	var direction = to_local(nav.get_next_path_position()).normalized()
	self.rays.rotation = direction.angle()
	if(ray_front.is_colliding()):
		var new_direction = get_clear_direction(rays)
		if(new_direction):
			direction = Vector2.RIGHT.rotated(rays.rotation + new_direction.rotation)
	velocity = direction * self.SPEED
	anim.play('walk_'+self.get_animation_direction(direction))
	if(prev_position.distance_to(point) > 30):
		move_and_slide()
	else:
		self.stop()
func get_clear_direction(rays):
	for ray in rays.get_children():
		if(!ray.is_colliding()):
			return ray
		return null

What exactly is the problem?
Since you are doing an rts you can consider to remove unit-collision completly (a lot of rts games dont have unit-collision)

Interesting. and what he can do if the units go at same target_position overlapping each other?

For this you can create unit formations so their target_position is different