Class FormationUtils
- Namespace
- WitShells.DesignPatterns.Core
Static utility class that generates world-space Pose lists for common tactical/game unit formations. Each method returns a list of positions and rotations that can be assigned to agents, NPCs, or any Unity objects.
public static class FormationUtils
- Inheritance
-
FormationUtils
- Inherited Members
Remarks
All methods are allocation-friendly – they return a new List<Pose> that the
caller owns. None of the methods move objects; callers apply the poses themselves.
Methods
GenerateBoxFormation(Transform, int, float)
Generates a square/rectangular box formation. Entities are arranged in a grid as close to square as possible.
public static List<Pose> GenerateBoxFormation(Transform transform, int numberOfEntities, float spacing)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities in the box.
spacingfloatGap between entities both horizontally and vertically.
Returns
- List<Pose>
GenerateCircleFormation(Vector3, float, int)
Generates a circular formation centred on center.
Each entity faces the centre of the circle.
public static List<Pose> GenerateCircleFormation(Vector3 center, float radius, int numberOfEntities)
Parameters
centerVector3The world-space centre of the circle.
radiusfloatRadius of the circle in world units.
numberOfEntitiesintHow many evenly-spaced poses to produce.
Returns
- List<Pose>
A list of Pose values arranged on the perimeter of the circle.
GenerateColumnFormation(Transform, int, float, int)
Generates a column formation where entities are arranged in multiple rows,
each row holding elementsPerRow entities side by side.
public static List<Pose> GenerateColumnFormation(Transform transform, int numberOfEntities, float spacing, int elementsPerRow = 2)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities in the column.
spacingfloatGap between entities in all directions.
elementsPerRowintNumber of entities per row (default 2).
Returns
- List<Pose>
GenerateDiamondFormation(Transform, int, float)
Generates a diamond formation with a single leader at the tip and expanding diagonal lines of entities behind. Additional entities beyond the first four continue the diamond pattern at each successive depth level.
public static List<Pose> GenerateDiamondFormation(Transform transform, int numberOfEntities, float spacing)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities including the leader.
spacingfloatGap between adjacent entities in the diamond.
Returns
- List<Pose>
GenerateEchelonFormation(Transform, int, float, float, bool)
Generates an echelon (staircase) formation where each entity is offset diagonally to the right or left and behind the previous one.
public static List<Pose> GenerateEchelonFormation(Transform transform, int numberOfEntities, float spacingX, float spacingZ, bool rightEchelon = true)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities in the echelon.
spacingXfloatHorizontal offset per step.
spacingZfloatDepth offset per step.
rightEchelonboolIf
true, the echelon trails to the right; otherwise to the left.
Returns
- List<Pose>
GenerateLineFormation(Transform, int, int, bool, bool)
Generates a straight-line formation relative to a Transform. The line runs along the right axis (horizontal) or forward axis (vertical) of the transform.
public static List<Pose> GenerateLineFormation(Transform transform, int numberOfEntities, int spacing, bool isCentered = false, bool isVertical = false)
Parameters
transformTransformReference transform that defines position and orientation.
numberOfEntitiesintTotal number of poses to place in the line.
spacingintGap between consecutive entities in world units.
isCenteredboolIf
true, the line is centred on the transform's position.isVerticalboolIf
true, the line runs along the forward axis; otherwise the right axis.
Returns
- List<Pose>
GenerateLineFormation(Vector3, Vector3, int)
Generates a straight-line formation between two explicit world positions.
All entities face the direction from start to end.
public static List<Pose> GenerateLineFormation(Vector3 start, Vector3 end, int numberOfEntities)
Parameters
startVector3World-space start point of the line.
endVector3World-space end point of the line.
numberOfEntitiesintNumber of evenly-spaced poses along the line.
Returns
- List<Pose>
GenerateTriangleFormation(Transform, int, float)
Generates a triangle formation where each successive row has one more entity than the previous, starting from a single entity at the front.
public static List<Pose> GenerateTriangleFormation(Transform transform, int numberOfEntities, float spacing)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities to place.
spacingfloatGap between entities within a row and between rows.
Returns
- List<Pose>
GenerateVFormation(Transform, int, float, float)
Generates a V-shaped formation (two diagonal lines diverging from the front). The first entity is placed at the tip; subsequent entities fan out on each side.
public static List<Pose> GenerateVFormation(Transform transform, int numberOfEntities, float spacingX, float spacingZ)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities in the V.
spacingXfloatHorizontal spacing between consecutive entities on each arm.
spacingZfloatDepth offset per step along the forward axis.
Returns
- List<Pose>
GenerateWedgeFormation(Transform, int, float, float)
Generates a wedge (arrowhead) formation with a single leader at the front and two diverging lines trailing behind.
public static List<Pose> GenerateWedgeFormation(Transform transform, int numberOfEntities, float spacingX, float spacingZ)
Parameters
transformTransformReference transform providing position and orientation.
numberOfEntitiesintTotal number of entities including the leader.
spacingXfloatHorizontal gap per step along each trailing arm.
spacingZfloatDepth gap per step behind the leader.
Returns
- List<Pose>