Polarith AI
1.8
Formation Class Referenceabstract

Description

This class extends the SteeringBehaviour through adding general local information about an agent's position inside of a formation.

The specific shape is defined in derived behaviours.

Formation computes the position of a single agent as part of a formation, i.e., it's decentralized. The position of a single agent is primarily based on the Size of the whole formation, the PositionInFormation as its place inside the formation, and the Spacing as horizontal and vertical distance between the agents.
AIMFormation.TargetObject, AIMFormation.TargetPosition, or AIMFormation.TargetTag may be considered in ComputePosition() in derived classes to move the formation to a specific position or to follow an object that deals as target agent for the whole formation.
The agents' computed target position results in SteeringBehaviour.ResultDirection as a vector from its current position towards its target position. The SteeringBehaviour.ResultMagnitude is based on the DistanceMapping. Note that the mapping can't be inverse.
The agent may slow down near its target position within the ArriveRadius, or accelerate between the InnerCatchUpRadius and the OuterCatchUpRadius to move a faster than its neighboring agents. Thus, it's able to keep up to its target position even if the formation rotates. The acceleration is scalable with CatchUpMultiplier.

Every derived Formation needs to implement ComputePosition() to set the exact position based on the specific formation shape.

Base back-end behaviour of every derived AIMFormation

Inheritance diagram for Formation:
SteeringBehaviour PerceptBehaviour< SteeringPercept > FormationArrow FormationBox FormationCircle FormationCross FormationLine FormationV

Public Fields

Vector3 ResultDirection
 The direction vector used for obtaining objective values. More...
 
float ResultMagnitude
 The magnitude value used for obtaining objective values. More...
 
int TargetObjective
 Defines the objective for writing values. More...
 
float MagnitudeMultiplier = 1f
 Is multiplied to the ResultMagnitude in order to weight between different behaviours. More...
 
float SensitivityOffset
 Is added to the Structure.Sensitivity as threshold for writing objective values. More...
 
ValueWritingType ValueWriting = ValueWritingType.AssignGreater
 Sets the type for writing objective values. More...
 
LayerBlendingType LayerBlending = LayerBlendingType.None
 Sets the operation for blending the behaviour results into the context. More...
 
LayerNormalizationType LayerNormalization = LayerNormalizationType.None
 Sets the method for normalizing intermediate objective values while they are blended into the context. More...
 
MappingType ValueMapping = MappingType.InverseLinear
 Sets the mapping type for obtaining objective values. More...
 
bool UseSignificance = true
 Determines if the SteeringPercept.Significance (if there is a AIMSteeringTag) is multiplied to the ResultMagnitude in order to weight between different percepts. More...
 
bool UseSensorProjection = true
 If true, Sensor.ProjectionMode is used as VectorProjection. More...
 
VectorProjectionType VectorProjection = VectorProjectionType.None
 Sets the type for projecting the perceived vector data into a plane. More...
 
PresetVelocityType PresetVelocity = PresetVelocityType.None
 If the value is anything other than PresetVelocityType.None, a game object's rotation and default forward direction is used to approximate its actual velocity. More...
 
PredictionType Prediction = PredictionType.None
 If set to anything other than PredictionType.None, the position of the Self percept is updated according to the given velocity. More...
 
float PredictionMagnitude = 0.0f
 Scales the velocity vector used for predicting the possible future position of an agent if Prediction is set to PredictionType.PredictionMagnitude. More...
 
readonly IList< T > Percepts
 All percepts which are relevant for an agent. More...
 

Protected Fields

int size = 1
 Maximum number of agents in the formation. More...
 
int positionInFormation = 0
 Logical position of the agent in the formation, e.g. More...
 
float spacing = 5f
 Distance between each agent in the formation. More...
 
float arriveRadius = 0f
 Radius within the agent slows down to arrive the target position. More...
 
float innerCatchUpRadius = 0f
 Inner radius within the agent keeps its to keep next to the target position. More...
 
float outerCatchUpRadius = 0
 Outer radius within the agent accelerates to keep next to the target position. More...
 
float catchUpMultiplier = 1f
 An additional multiplier to obtain values bigger than the standard magnitude. More...
 
NonInverseMappingType distanceMapping = NonInverseMappingType.Linear
 Specifies the mapping type of the distance from the agent to its target position. More...
 
int layers = 1
 The number of layers to cover agents dynamically (grows in-depth). More...
 
readonly SteeringPercept self = new SteeringPercept()
 The data of the associated agent itself (read only). More...
 
readonly SteeringPercept percept = new SteeringPercept()
 The data of the currently processed percept (read only). More...
 
IList< float > objective
 Quick access to the currently processed objective. More...
 
ISensor< Structuresensor
 Quick access to the currently processed sensor. More...
 
IReceptor< Structurereceptor
 Quick access to the currently processed receptor. More...
 
Structure structure
 Quick access to the currently processed structure. More...
 
Vector3 velocity = Vector3.forward
 The forward direction the agent moves towards and/or looks at by default. More...
 

Properties

int Size [get, set]
 Maximum number of agents in the formation. More...
 
int PositionInFormation [get, set]
 Logical position of the agent in the formation, e.g. More...
 
float Spacing [get, set]
 Distance between each agent in the formation. More...
 
float ArriveRadius [get, set]
 Radius within the agent slows down to arrive the target position. More...
 
float InnerCatchUpRadius [get, set]
 Inner radius within the agent keeps its to keep next to the target position. More...
 
float OuterCatchUpRadius [get, set]
 Outer radius within the agent accelerates to keep next to the target position. More...
 
float CatchUpMultiplier [get, set]
 An additional multiplier to obtain values bigger than the standard magnitude. More...
 
NonInverseMappingType DistanceMapping [get, set]
 Specifies the mapping type of the distance from the agent to its target position. More...
 
int Layers [get]
 The number of layers to cover agents dynamically (grows in-depth). More...
 
override bool forEachPercept [get]
 Returns true since only percept steering is supported. More...
 
override bool forEachReceptor [get]
 Returns false since only percept steering is supported. More...
 
override SteeringPercept Self [get, set]
 The data of the associated agent itself. More...
 

Public Methods

abstract Vector3 ComputePosition ()
 Abstract method for building up the formation (compute position for individual agent). More...
 
void UpdateResultPosition ()
 Recomputes and sets the resulting position for the agent in the formation. More...
 
override void Behave ()
 This method executes the main context steering algorithm and is called within Context.Evaluate in order to set/modify objective values for the associated Context.Problem. More...
 

Protected Methods

override void PerceptSteering ()
 Processes the steering algorithm for each percept using the same data for each processed receptor. More...
 
void ChangeOrientation (Vector3 up, ref Vector3 vec)
 Flips a vector from XY-plane according to an up vector. More...
 
virtual bool StartSteering ()
 Gets called at the beginning of the context steering algorithm for each processed percept and should be used to pre-compute things like distances or to check whether a percept is relevant at all. More...
 
virtual void ReceptorSteering ()
 This method gets called for each active shape receptor for each processed percept. More...
 
Imprint