6. Flocking
Flocking with 3D movement.
This sample explains usage of neighbor behaviors through classical use case - flocking. Flocking here is the combination of three behaviors - Alignment, Cohesion, and Separation. All these behaviors are included in the default behaviors.
The first folder - 1. Behaviors contains a scene for each behavior where the behavior is visualized and a scene where the combination of the behaviors is visualized. Then there is a sample scene with flocking for each movement system. For example folder 2. 2D.
1. Behaviors
All movement systems and behaviors can be toggled with an IsActive flag. In the following scenes, the IsActive is set to false on the Movement2DAuthoring to make it easier to understand.
- Cohesion
- Separation
- Alignment
- Combination
- Steering System Asset
- Prefab
This scene visualizes the result of the CohesionJobWrapper. This behavior makes the entity group up with it's neighbors. The yellow arrow visualizes VelocityResult. The direction is DesiredDirection, the length is proportional to DirectionDesire. The radius where the behavior detects neighbors is shown with the yellow circle.
This scene visualizes the result of the SeparationJobWrapper. It seperates the entity from it's neighbors.
This scene visualizes the result of the AlignmentJobWrapper. It aligns the entity's direction with it's neighbors.
This scene visualizes the combination of all three behaviors responsible for flocking - CohesionJobWrapper, AlignmentJobWrapper, SeparationJobWrapper.
FlockingBehaviorsSteeringAsset:
- Main Tag -
_6_SampleBehaviorsTagComponent - Neighbor Behaviors - [
CohesionJobWrapper,AlignmentJobWrapper,SeparationJobWrapper] - Prefab - EntityFlocking
All the scenes in the 1. Behaviors folder share this SteeringSystemAsset, because all the entities share the _6_SampleBehaviorsTagComponent tag.
Neighbor Behaviors

Behavior Components:
Other Components:
It does not matter that the scenes use different prefabs than the one referenced in FlockingBehaviorsSteeringAsset, as long as their SteeringEntityAuthoring has _6_SampleBehaviorsTagComponent.

2. 2D
- Scene
- Steering System Asset
- Prefab
2D Movement
In this scene you can toggle multiple different subscenes which have different setups of CohesionAuthoring, AlignmentAuthoring, SeparationAuthoring. If an entity goes over a border set on BoxLimiterAuthoring, it is teleported to the oposite side.
Flocking2DSystemAsset:
- Main Tag -
_6_Sample2DTagComponent - Neighbor Behaviors - [
CohesionJobWrapper,AlignmentJobWrapper,SeparationJobWrapper] - Simple Behaviors - [
GoForwardJobWrapper] - Prefab - EntityFlocking
Neighbor Behaviors

Simple Behaviors
GoForwardJobWrapper makes entity keep movement direction with constant speed. It is crucial to have at least one behavior which returns VelocityResult with positive DesiredSpeed and SpeedDesire. Otherwise the entities will not move anywhere.

Behavior Components:
Other Components:

3. 3D
- Scene
- Steering System Asset
- Prefab
3D Movement
In this scene there are three different subscenes containing flocks of different sizes. The larger flock has a more optimized, but simpler neighbor query. This scene also shows usefullness of MultiHomingAuthoring which makes the entities stay within given areas. In the subscenes, the larger the flocks, the larger the homing radii on the HomingComponents. Second new behavior is AlignUpJobWrapper, it prevents the entities from flying up or down at too steep angle.
Flocking3DHugeSystemAsset:
- Main Tag -
_6_Sample3DLargeTagComponent - Neighbor Behaviors - [
CohesionJobWrapper,AlignmentJobWrapper,SeparationJobWrapper,MultiHomingAuthoring] - Simple Behaviors - [
GoForwardJobWrapper,AlignUpJobWrapper] - Prefab - EntityFlockingHuge
Neighbor Behaviors

Simple Behaviors
GoForwardJobWrapper makes entity keep movement direction with constant speed. It is crucial to have at least one behavior which returns VelocityResult with positive DesiredSpeed and SpeedDesire. Otherwise the entities will not move anywhere.

Behavior Components:
GoForwardAuthoringAlignUpAuthoringCohesionAuthoringAlignmentAuthoringSeparationAuthoringMultiHomingAuthoring
Other Components:

4. 2.5D
- Scene
- Steering System Asset
- Prefab
2.5D Movement
This scene shows a flock set up on terrain, bordered by walls. The walls are a third option so far to constraint the entities within an area. The previous two options were BoxLimiterAuthoring and MultiHomingAuthoring.
Flocking25DSystemAsset:
- Main Tag -
_6_Sample25TagComponent - Neighbor Behaviors - [
CohesionJobWrapper,AlignmentJobWrapper,SeparationJobWrapper] - Simple Behaviors - [
GoForwardJobWrapper] - Prefab - EntityFlocking
Neighbor Behaviors

Simple Behaviors
GoForwardJobWrappermakes entity keep movement direction with constant speed. It is crucial to have at least one behavior which returns VelocityResult with positive DesiredSpeed and SpeedDesire. Otherwise the entities will not move anywhere.

Behavior Components:
Other Components:
