AI path agent want to move into obstacle/other unit

I am trying to implement rts like unit movement. I am using AIPath and setting multitarget path around targets so that different faction1 units can surround faction2 units. I have attached a screenshot below where after I enabled RVOCollider on stop (custom rvo collider using 12 edged polygon), faction 1 units still trying to walk into the collider (highlighted with red arrow). Where it should go around like yellow arrow in the image.

I have tried with RVO Collider and without (just local avoidance with each other), either stopped them from trying to walk into their friendly units.

My agent radius is 1, 1.5 and 2.5. My grid graph is current set to node size = 1 (I tried 0.5 as well). I tried the grid graph collision testing to include and exclude units, but I don’t think it works as the graph is already scanned and I didn’t trigger update after initialization.

I have followed this post below to set Max Nearest Node Distance to 0.01 but it didn’t help.

By the way, the pathing is also incorrect when the destination doesn’t have enough space/the path toward it is to narrow to cross. For now, I think it is related to this collider issue.

Update:
I searched around and found this post: RVO and Path not working well together where it says the RVOCollider isn’t design to affect pathing. I then try to use the DynamicGridObstacle, but it doesn’t seem to work with a CapsuleCollider (it is not a simple Bound). I am going to try out just using a box collider and see what the quality of the pathfinding would be.

I tried using a BoxCollider and DynamicGridObstacle on each unit when they stop moving so that other units will try to walk around them. But with low amount of grid nodes, the precision is quite bad. My unit radius is 1. With higher amount of nodes 300x300 (0.2x0.2 unit per node), it is quite laggy even on my PC to recalculate graph on the fly. I guess the next thing I am going to try is to use recast graph and navmesh cutting, which I feel is somewhat similar to unity navmesh.

Please let me know if this is the right way to go. Thanks!

Hi

Yes, RVO does not affect pathfinding.
The best option for surround in my opinon, is to use the beta version, and then mark agents which have reached their target point (I’m assuming some units are attacking their opponent when in melee range) as locked (this is a field on the RVOController). The beta version has better support for avoiding locked agents.

1 Like

Thanks for the reply. And just to confirm, I can still use grid graph, right?

Yes. RVO work independently of graph type.

I have tried beta version and the surrounding behavior is great. However, I started to encounter another problem because of this. When using local avoidance, the AI path won’t stop even if all target is not-reachable, as the target point is occupied by another locked agent but the graph is not being cut. This causes agent to run around randomly, which is somewhat okay. But when the walkable area is rather small, and a lots of agents are pushing each other, it can push some agents off grid and cause them to snap back to the center of the map.

I have attached screenshots below. Blue circled units are fighting and locked (the RVO controller option), they occupies the entire width of the battleground. All units other than the blue circled ones now have no path to an enemy realistically, but they still have path generate (image 2), so they walk around and pushes each other out of the grid (green arrow). Because I have Constrain Inside Graph option turned on, they will be snapped into the center of the battleground (overlapping agents in the center of image 1). If I turn off Constrain Inside Graph, they will just be left outside of the walkable area and stuck there.


Any suggestions on how to solve it? I feel like using Recast graph and navmesh cutting could be a walkaround solution as the cutting the graph will stop AIPath generate a path so they would just hold still.

Any updates please? Thanks!

Hi

You are correct, without using navmesh cutting or some other kind of graph update, the moving agents have no way of realizing that they cannot reach their destination, and so will try to move around the locked agents in any way they can.

1 Like

Thanks for the answers!

I am able to get the behavior roughly correct with recast graph and navmesh cutting. However, I encountered several issues to make it flawless for my usage.

Issue 1:
In the image below, the yellow line(highlighted) is the previous path calculated using StartMultiTargetPath. I want the agent the keep moving on the previous calculated path when possible so that it won’t abruptly repath and turn around to another target. However, the previous path is obviously not walkable anymore as the graph is cut by other stopped unit. But when I do IsPathPossible(path.path) (this path is the callback parameter from StartMultiTargetPath), it still returns a true result. Do you know what could be the possible reason?

Also when the path is not possible like above, even though the IsPathPossible return true incorrectly, the agent knows it is indeed not walkable. So it would stutter back and forth within a 0.2 unit radius.

Issue 2:
The unit slows down when the path is a bit complex and near to the end. See red line example in the same image above. I searched around for all possible issues but couldn’t figure out why it is. My RichAI setting is like below snapshot.
I have big acceleration, 0 slowdown time, 0 wall force and dist. Also, stopped agent will enable navmesh cut and disable RVOController (to avoid weird local avoidance behavior). By the way. my agent would stop by my script using RichAI.canMove = false if it is close to the destination.

RichAISettings

Issue 3:
StartMultiTargetPath sometimes doesn’t return the shortest path . The yellow lines are the destination points I sent to the function. However, it picked the red line instead of the white line.

This is the reason a don’t want to constantly repathing above because it can make the agent walk back and forth, because each repath yield different shortest path and the agent cannot reach any of those endpoint.


How I call StartMultiTargetPath:

seeker.StartMultiTargetPath(transform.position,
                            possibleDestinations,
                            false,
                            path =>
                            {
                                pathAvailable = path.error == false;
                                if (!pathAvailable)
                                {
                                    StopPathing();
                                    return;
                                }

                                xxxx // start moving
                            });

My Pathfinder Settings for reference

Hi, could you please help me on this issue? Thanks!

I found the slow movement issue is related to RVO behavior around wall (a simple box collider)? But I haven’t figure out how to fix yet.

Today the multitarget path failed to calculate path multiple times when there is obviously a path. The unit on the left failed to find a path around to the back of the dragon. The yellow lines indicates the path targets I am setting.

Path Failed : Computation Time 0.00 ms Searched Nodes 0
Error: Couldn’t find a valid node close to the any of the end points
Path Number 270 (unique id)
UnityEngine.Debug:LogWarning (object)
AstarPath:LogPathResults (Pathfinding.Path) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/AstarPath.cs:817)
AstarPath:b__122_1 (Pathfinding.Path) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/AstarPath.cs:1291)
Pathfinding.PathProcessor:CalculatePathsThreaded (Pathfinding.PathHandler) (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Misc/PathProcessor.cs:512)
Pathfinding.PathProcessor/<>c__DisplayClass26_0:<.ctor>b__0 () (at Library/PackageCache/com.arongranberg.astar@4.3.61/Core/Misc/PathProcessor.cs:145)
System.Threading.ThreadHelper:ThreadStart ()

The slow down issue seems completely go away after I set Obstacle Time Horizon to 0. I guess when it is not 0, it would try to avoid other box colliders even though those collider doesn’t have RVO attached to it.

I have tweaked a lot of things and it seems most of the problem is resolved. I will create a new thread for any other questions.

Slow movement issue is resolved by removing RVO behavior around walls (reduce obstacleTimeHorizon to 0).

The path calculation is resolved by increase AstarPath.maxNearestNodeDistance
Maximum distance to search for nodes.