How to handle a group of NavigationAgent2D's arriving at the same location?

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

I’ve read into and am basically using a setup as suggested similar to 2D navigation overview — Godot Engine (latest) documentation in English including Avoidance and setting the (safe) velocity in the computed callback:

func _on_navigation_agent_2d_velocity_computed(safe_velocity: Vector2) -> void:

It all works so far, but when sending multiple Units (that have NavigationAgent2D’s) to the same target location, they “fight” for the destination place and push each other around endlessly.

I can understand why this happens, but can’t figure out a good way to implement a “group behaviour”.
What I want would basically be an RTS style group command resulting in units moving towards the destination, but stopping if another unit /navagent2d is already at standing at this (or surrounding) location.

Any suggestions on how to do this?

:bust_in_silhouette: Reply From: Gluon

I should caveat this by saying that I am on 3.5 still not godot 4 but it seems to me this should be easily achieved. Put an area2d or 3d depending on your game around the unit stretched out a little so it can detect other units around it. Then have a boolean guard set as default to true, only run your code when the area2d/3d does not detect a unit in the area2d/3d so now your unit only moves when it doesnt see another unit close by.

sometimes … :slight_smile: yes that totally sounds like a solution to pursue.
Thank you!

chrisme | 2023-01-23 13:42