Surrounding the target

Hi, I’m using the free version. I just want to know if it is possible that a number of agents will surround the target instead of falling in line? I am using a script that implements AIPath.

How to make them surround not like this (image) ?

Also, thanks for this project, very helpful :slight_smile:

Take a look at this topic, it should give you some ideas~

If your still at a loss, let me know and I will write you some sudo code*

1 Like

Hi Burdock

I’m a bit confused. Correct me if I’m wrong.

When the agent reached the closest distance it is marked as stop, then others who collide with this stopped agents have to make repath(or how to make them repath that will make them treat the stopped agent as a obstacles)?


Well, in the other topic there was no object that had to be “surrounded” so I would go for a different approach~

Since your working with the Free A* pathfinding, sadly you cant use any local avoidance. The easiest way I can think off the top of my head is writing a new script that works like so:

Basically you want to make a cluster of Paths with each ones end point at the next best location touching your Target.

Here is an example

If the @'s are your units and the #'s is your target

If there is only one unit, it will find the closest location touching the target~
-> …@#

If there are more units, each proceeding unit will find the next best location~

If there are more units then spaces, it will start a new row(Or a new orbit, or whatever you want to call it)~
-> @@#@

If you need some sudo code to get you started I can help with that too~

Thanks Burdock, I got the idea, the implementation will be easy :slight_smile:

I’m have the same situation and I’ve tried many ways to make my army to surround a building but I can’t figure it out.
I’m using A* Pro(beta 4.1.1) and RVO Controller. When my army get to the target only 1 unit starts attacking and the others just walk around trying to get to the same position.
I bought the Behavior Designer Movement and Tactical addons but the Tactical add-on use Nasmesh, I’m using Layer Grid graph instead of Navmesh to be able to drop buildings(towers, walls, etc) snapped to grid at game time.
My game is RTS.
Any help will be very much appreciated as I’m struggling with this.


Something that I have had success with in another game is making each character have say 6 or 8 surround points at something like a 1m or 2m distance from the character placed in a circle. When an enemy wants to attack a character it reserves one of those surround points and tries to move to it. When another enemy wants to attack the same character it will look for the closest surround point that is not already reserved by another enemy.

Hi Aron,
Thanks for the help.
That’s what I ended up doing.
The issue I’m facing is that doesn’t matter what I try the character doesn’t look at the actual target(player/building), they just look at the points. Even when setting to rotate towards and lookat the target(not the points).


I think you will have to either override the movement scripts or make modifications for them for that to work. The movement script right now have no way of knowing where you want them to look.

I’m using the rotate towards from the movement addon for behavior designer(which integrates with A *). I’m trying to debug it to figure out what’s going on and then maybe clone it on a new class and send the fix to the guys or ask them to fix it…

Got the rotate towards task fixed, it indeed has a bug when not using a GameObject as target but a Vector3, it doesn’t do the new position calculation properly… I’m going to tell Behavior Designer guys about this issue.

I got a new issue that I need your help or someone else. Basically, when surround the building I just use 8 points around the building, on this case it’s a wood tower and the tower has 4 legs. How do I block the AI going underneath the tower to reach the point on the other side instead of going around it? I mean it’s just walks underneath, and once it reaches the point(target) it turns to attack the tower but it’s underneath the tower. I want to go around and, not through it…
So, I tried adding a cube underneath the tower and setting it as obstacle but doesn’t stop them. If the cube is lower enough the just step on top of it and go through.

I think I found solution…
I tested setting the whole tower as obstacle and scanning the graph again and run it. The AI doesn’t go through the tower anymore, they go around to their specific target points.
I’ll try to use Graph Update Object for runtime building placement…

Sorry if I’m posting too many dummy questions, your documentation is great but sometimes it takes while to understand how and when to use the A* APIs.

So, after having success with the issues I presented before, I got a new one. As per image below the unit get stuck behind another unit if its path cross that unit node. Eventually the blocked unit goes around it but it takes while.

I thought about trying to blocked the nodes using the code for Turned Based games

	 public class SkeletonAIAgent : AIPath {

		public BlockManager blockManager;
		public List<SingleNodeBlocker> obstacles;
        BlockManager.TraversalProvider traversalProvider;

		public new void Start () {

			traversalProvider = new BlockManager.TraversalProvider(blockManager, BlockManager.BlockMode.OnlySelector, obstacles);

           // Call Start in base script (AIPath)

		protected override void Update () {

			// Create a new Path object
			path = ABPath.Construct(transform.position, target.position, null);
			// Make the path use a specific traversal provider
			path.traversalProvider = traversalProvider;
			// Calculate the path synchronously
			if (path.error)
				Debug.Log("No path was found");
				Debug.Log("A path was found with " + path.vectorPath.Count + " nodes");
				// Draw the path in the scene view
				for (int i = 0; i < path.vectorPath.Count - 1; i++)
					Debug.DrawLine(path.vectorPath[i], path.vectorPath[i + 1],;


But this fails with "ArgumentException: You are releasing a path which is not claimed at all (most likely it has been pooled already). Are you releasing the path with the same object (Skeleton_footman (7) twice?
Check out the documentation on path pooling for help.
The obstacles are all units except the unit owning the script. I do same thing for all units.

So, how can I implement a solution for this issue?

I’m posting everything here on this thread because I think it’s still an issue related to surround a target.

I figured out that I can’t use the Turned Based code to block the node, I found a comment on the code saying it can’t be used for movement… So, I’ll try some other suggestions I found in the forum.