Formations Pack for Behavior Designer Pro

The Formations Pack is an add-on for Behavior Designer Pro that allows you to create various formation patterns for groups of agents. While the pack contains 15 built-in formations the system is design to be easily extendable for any formation type. The default set of Formations Pack tasks use Unity’s navigation mesh to traverse the world. The Formations Pack doesn’t do the actual movement – it instead sets the destination for the underlying pathfinding implementation (Unity’s NavMesh, A* Pathfinding Project, etc).

Adding a New Formation

Add Task to your Behavior Tree
  1. In your behavior tree, right-click and select Add Task.
  2. Navigate to the Formations Pack category or type the name of the formation task that you want add.
  3. Choose one of the available formation types.
Changing the Pathfinder
The Formations Pack uses a pathfinder to control agent movement. By default, it uses Unity’s NavMesh implementation. Integration pathfinders can be downloaded from the Downloads page with your Formations Pack invoice number.
Configure the Formation Base Settings
Each formation task has common settings organized into three categories:
Formation Group Settings
  • Is 2D: Is this formation being used in a 2D space?
  • Formation Group ID: Integer that defines which group this agent belongs to.
  • Force Leader: When enabled, this agent will be forced as the leader of the group.
Leader Settings
  • Target Position: The position the formation will move to.
  • Formation Direction: How the formation should be oriented:
    • Transform Direction: Uses the leader’s forward direction.
    • Movement Direction: Uses the direction from current position to target.
    • Specified: Uses a custom vector you define.
  • Specified Direction: Forward direction if using “Specified” orientation.
  • Move To Initial Formation: If enabled, agents first create the formation before moving.
  • Fail On Agent Removal: If enabled, the task fails if any agent leaves the formation.
  • Update Unit Locations On Agent Removal: If enabled, formation positions update when agents leave.
Formation Settings
  • Rotation Speed: Degrees per second agents rotate.
  • Rotation Threshold: Angle threshold for stopping rotation.
  • Out Of Range Distance Delta: Distance at which an agent is considered out of range.
  • In Range Distance Delta: Distance at which an agent is considered back in range.
  • Out Of Range Speed Multiplier: Speed adjustment for out-of-range agents.
  • Stuck Duration: Time with zero velocity before agent is considered stuck.
  • Stop On Task End: Whether to stop movement when the task ends.
Configure Formation-Specific Settings
Each formation type has unique parameters to control its shape and behavior. See the tooltip for a description of each field.

Formation Groups

Formation groups allow you to organize multiple agents into cohesive units that move together. Agents in the same group will follow the formation’s rules and positions.
Setting Up Formation Groups
Basic Setup
  1. Assign the same Formation Group ID to all agents in a formation.
  2. The first agent added becomes the leader by default.
  3. Alternatively, set Force Leader on an agent to make it the leader.
Using Multiple Groups
  1. Assign different Formation Group ID values to create separate formations.
  2. Each group operates independently with its own leader and target position.

Formation Start Delay

The FormationsManager is a singleton that has a built-in delay before formations start moving, allowing all agents to register themselves within the group. When a Formations Pack task starts it will add the FormationsManager if this singleton is not present in the scene. The start delay can be configured by adding this component to your scene.

Creating a Custom Formations

New formation types can be created by extending the FormationsBase class.The FormationsBase abstract class provides the foundation for all formations. When creating a custom formation, you’ll need to:
  1. Inherit from FormationsBase.
  2. Implement the abstract CalculateFormationPosition method.
  3. Define formation-specific parameters.
  4. Override additional methods for special behavior.

Below is an example implementation:

using Opsive.BehaviorDesigner.AddOns.FormationsPack.Runtime.Tasks;
using UnityEngine;

public class MyFormation : FormationsBase
{
    /// <summary>
    /// Should the optimal indicies be assigned? This should be set to false for random formations.
    /// </summary>
    public override bool AssignOptimialIndicies => true;

    /// <summary>
    /// Calculate the position for this agent in the skirmisher formation.
    /// </summary>
    /// <param name="index">The index of this agent in the formation.</param>
    /// <param name="totalAgents">The total number of agents in the formation.</param>
    /// <param name="center">The center position of the formation.</param>
    /// <param name="forward">The forward direction of the formation.</param>
    /// <param name="samplePosition">Should the position be sampled?</param>
    /// <returns>The position for this agent.</returns>
    public override Vector3 CalculateFormationPosition(int index, int totalAgents, Vector3 center, Vector3 forward, bool samplePosition)
    {
        return Vector3.zero;
    }
}