Leader Follow - Followers acting erratic and passing the leader when he stops

Snowfrog

New member
I'm not getting the kind of behavior I was hoping for out of leader follow. When the leader, a player controlled object with a Character Controller, comes to a stop, many of the followers speed passed him before coming to a stop themselves. Here is a short video of what is going on: https://streamable.com/9mt6qs

I'm trying to achieve something very similar to the minions following behavior in the game Overlord as can be seen in this clip:


I have all three add-ons to BD so feel free to suggest something other than leader follow if you think it will get the job done better.
 
When there are multiple following agents those agents will settle into position around the character. You have a couple of options:

1. Modify the LeaderFollow task so it uses a different algorithm to have the characters stay behind the leader. This would be modified within LeaderFollow.OnUpdate. Most likely you wouldn't use the DetermineSeperation method.
2. Use the regular Follow task. This doesn't take into account other agents so there may be some fighting for position but it could be a start.
 
Thanks for the suggestions. Having had a look at the Formation add-on, I think that might be a better option for me. I'm experimenting with it at the moment and I'm having a hard time figuring out the concept of the leader. I have added the triangle behavior to a bunch of follower objects and to my player object and have assigned my player object to the leader parameter in the inspector but that does not seem to work. I can't quite figure out what to do here. Any help will be appreciated.

Edit: I have figured out that the problem was that my player object had leader set to itself when if fact it should be set to null. But now I have another problem. The agents get into position when I start play but after that they stop following the leader. I have tried to correct this by setting Restart When Complete on all agents and the leader but that also doesn't work. Well, not quite. One of the agents keeps following but all the other agents don't move and I get the following error in the console:
Code:
ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at <437ba245d8404784b9fbab9b439ac908>:0)
System.ThrowHelper.ThrowArgumentOutOfRangeException () (at <437ba245d8404784b9fbab9b439ac908>:0)
System.Collections.Generic.List`1[T].set_Item (System.Int32 index, T value) (at <437ba245d8404784b9fbab9b439ac908>:0)
BehaviorDesigner.Runtime.Formations.Tasks.FormationGroup.UpdateMoveStatus (System.Int32 index, BehaviorDesigner.Runtime.Formations.Tasks.FormationGroup+MoveStatus status) (at Assets/Behavior Designer Formations/Scripts/Tasks/FormationGroup.cs:280)
BehaviorDesigner.Runtime.Behavior.SendEvent[T,U] (System.String name, T arg1, U arg2) (at <ddb5579d0d23478c9f73ec2f99600079>:0)
BehaviorDesigner.Runtime.Formations.Tasks.FormationGroup.OnUpdate () (at Assets/Behavior Designer Formations/Scripts/Tasks/FormationGroup.cs:443)
BehaviorDesigner.Runtime.BehaviorManager.RunTask (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree, System.Int32 taskIndex, System.Int32 stackIndex, BehaviorDesigner.Runtime.Tasks.TaskStatus previousStatus) (at <ddb5579d0d23478c9f73ec2f99600079>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick (BehaviorDesigner.Runtime.BehaviorManager+BehaviorTree behaviorTree) (at <ddb5579d0d23478c9f73ec2f99600079>:0)
BehaviorDesigner.Runtime.BehaviorManager.Tick () (at <ddb5579d0d23478c9f73ec2f99600079>:0)
BehaviorDesigner.Runtime.BehaviorManager.Update () (at <ddb5579d0d23478c9f73ec2f99600079>:0)
 
Last edited:
It looks like there is still some issue with the current setup. The leader field should be blank for the leader agent, and the rest of the agents should point to that leader. Is that what you have setup? If you compare it to the demo scene do you have a similar setup?
 
Yep, that's what I got. The leader field is blank for the leader agent and the rest of the agents point to the leader. The only difference between my setup and the demo scene, as far as I can tell, is that the leader agent is controlled by the player with a Character Controller and also that my agents have their "Start When Enabled" checkmarked and the agents in the demo scene do not.

The leader:
1593625613712.png

The other agents:
1593625823632.png

All agents:
1593625561780.png
 
I have pinpointed where the error occurs. As you can see the moveStatus collection only has one entry at index 0 but it is trying to set index 1. You can see the context of the class instance on the left if it helps. I can't quite wrap my head around how FormationGroup works haven't quite figured out when moveStatus is created and why it only has one entry. I have three agents in the formation and I'm guessing that moveStatus should therefore have three entries.
1593631528157.png
 
The moveStatus array will only be populated for the leader. This variable keeps track of the current state of all of the followers. Does AddAgentToGroup get called twice before UpdateMoveStatus with an index of 1? It should be called first on the leader, and then from any of the following agents.

For now I would disable restart when complete just to try to get the basics working. Also, just confirming, but I am assuming that Player is also an AI agent? It looks like it is but just want to verify.
 
Player is not an AI agent, it is a player controlled object and is controlled with a Character Controller component.

Maybe I'm going about this the wrong way. Instead, I'll tell you what I'm trying to achieve and maybe you can suggest the best way for me to get what I want with as little customization as possible. I bought Behavior Designer in large part because of the formation and movement add-ons thinking they did what I wanted out of the box. It would be a shame if in the end I have to code almost everything from scratch.


Here are my requirements:
1) A group of AI agents must closely follow a player-controlled character in a somewhat orderly fashion.
2) When the player-controlled character stops, the ai agents also stop in a somewhat orderly fashion. When he moves again, they follow.
3) I can add agents to the group of followers dynamically.
4) I can remove agents to the group of followers dynamically.

At this point, I don't much care what formation they are in. I just want to achieve these four requirements.
 
Last edited:
Ahh, that's the issue. The formations task assume the leader is an AI agent.

I actually think that your best bet is to use the Follow task from the Movement Pack as a starting point. This task can follow any arbitrary GameObject and is a lot easier to configure. This will satisfy all four of your requirements, but the AI agents may bunch up together. You could get around this by setting a different offset for each agent.
 
Top