8. Flocking with Predator
Flocking combined with avoiding a predator (red) in 2D and 3D.
This sample shows combination of flocking and predator avoidance. There are two subscenes one for 2D and one for 3D. Each subscene contains a flock of entities similar to previous example. The entities here use FleeJobWrapper to escape a predator. The predator uses SeekingJobWrapper to chase the entities. When the predator is not seeking anything, the WanderingJobWrapper makes it wander around randomly. This example also shows the usefulness of neighbor query groups. The entities can use one query to find their flockmates and another query with a different tag to find the predator.
- Scene
- Prey System Asset
- Prey Prefab
- Predator System Asset
- Predator Prefab
The subscenes contain one predator in red color and SpawnerAuthoring which spawns in a flock of entities. There is several HomeAuthoring which the entities use to stay in a general area. The same homes are used by both the predator and the prey entities.

PreySteeringSystemAsset:
- Main Tag -
_8_SampleTagComponent - Simple Behaviors - [
GoForwardJobWrapper] - Neighbor Behaviors - [
CohesionJobWrapper,AlignmentJobWrapper,SeparationJobWrapper,MultiHomingJobWrapper,FleeJobWrapper] - Prefab - PreyEntity2D (the same system is used for PreyEntity3D as well)
Neighbor Behaviors
The target entities to flee from are ones with tag _8_SamplePredatorTagComponent. There are three neighbor queries; first finds predators, second finds flockmates, third finds the homes. For each query, different behaviors are run.

Simple Behaviors

Behavior Components:
FleeAuthoringCohesionAuthoringAlignmentAuthoringSeparationAuthoringMultiHomingAuthoringGoForwardAuthoring
Other Components:
SteeringEntityAuthoringDesiredVelocityAuthoringMovement2DAuthoring(orMovement3DAuthoringfor PreyEntity3D)

Movement2DSteeringAsset:
- Main Tag -
_8_SamplePredatorTagComponent - Simple Behaviors - [
WanderingJobWrapper] - Neighbor Behaviors - [
SeekingJobWrapper,MultiHomingJobWrapper] - Prefab - PredatorEntity2D (the same system is used for PredatorEntity3D as well)
Neighbor Behaviors
Note that the target entities to seek are ones with tag _8_SampleTagComponent.

Simple Behaviors

Behavior Components:
Other Components:
