Multiple units with the same destination?

[Sorry if solution was mentioned earlier somewhere but I didn’t find it.]
When more than 1 “cube” unit has the same destination, they collide each others at this point and can’t stop pushing/rotating/jumping. How to tell each unit that if this point is unavaliable because of another unit, it should stay next to it?

Hi

This is a surprisingly tricky thing to do.
One thing that works reasonably well is to do this kind of check:

let D be the distance to the destination
let A be a list of all agents (including this one) inside a circle of radius D around the destination
let Area be the sum [a.radius*a.radius*pi foreach a in A], i.e the total area that the agents in A cover assuming they are circles
stop if Area > D*D*pi * 0.6, i.e if the density of agents is more than 60% inside that circle.

I have posted a test script that does this in this thread: Which options of the asset are best for RTS (like Starcraft II). It is not a perfect script, but it is a good start.
Note that in many cases you can use local avoidance (see https://arongranberg.com/astar/docs/local-avoidance.php) however you may still see some pushing depending on the acceleration and movement behaviors of your agents.

Maybe something simpler should be enough, but please describe what I have to change:
In example scene 2 with two obstacles, if destination point is “inside” this obstacle, robot stands near it. What settings are required for that effect? I’ve added dynamic grid obstacle to every “cube” in my scene and because they belong all to “selectableObjects” layer, in A* (with Astar Path script I’ve added “SelectableObjects” to Collision testing mask. But no changes at the end, still chaos near destination point :confused:

Hi

You cannot add a DynamicGridObstacle to something that also uses pathfinding (which I assume these ‘cubes’ do) as this will always cause them to make the grid where they stand unwalkable, so they will try to avoid themselves.

But I can add an empty object to my unit, give it some obstacles and there I can have Dynamic Grid Obstalce Script. And I can use 3 obstacles instead of 1. Can something like this work?

terra

(BTW local avoidance which you’ve proposed earlier is unable in free version of your packet :wink: )

Hi

Unfortunately not.
In your case the agents would still try to stand on the same point.

Ok … but if unit which reached the target activates 1 more obstacle, which will “close it” in a box, this target will be unavaliable, and next units will behave like I’ve described, Am I wrong?

EDIT: If this doesn’t work, would you like to tell me where should I attach your script (Which options of the asset are best for RTS (like Starcraft II)) to get wanted effect? Or is there somewhere a scene where I can look and see how it works? :slight_smile:

EDIT2, AFTER ARON’s post below (I can’t add anything more because I’m “new user”)

So long hours of testing before me :wink:
Of course, my idea showed with my paint images wouldn’t be the only one, it’s more like “for security”. Perhaps I’ll try to do something like in first “Sudden Strike” games: Selected Object from the sorted list (with 0 index) gets original targets. Then there’s a calculation for destination between object [0] and next object. If this distance is big, it’s multiplied by some kind of factor (bigger distance, lower factor), and a new target for next object is calculated.

Sorry if I discuss too much, but I’m still learning and I hope our discussion will be helpful for the others someday :wink:

Yes, that works, however it only works if the unit is stationary. Any paths it calculates will be completely incorrect.
So for summarize: you can add a DynamicGridObstacle component to the agents if you make sure that it is only enabled when the objects are stationary and that they do not calculate any paths while the component is enabled.
It might be tricky to use a DynamicGridObstacle component though as you will have to revert the nodes to be walkable when the unit is going to move again. It is probably easier to use a GraphUpdateObject from script, see: https://arongranberg.com/astar/docs/graph-updates.php