Creates a goal whose effect is to make an agent stay near the other agents in a specified group.
- iOS 9.0+
- macOS 10.11+
- Mac Catalyst 13.0+
- tvOS 9.0+
The agents with whom to stay close.
The maximum distance from other agents required for this goal to take effect.
The maximum angle, in radians, between an affected agent’s velocity and the direction toward the other agents required for this goal to take effect.
A new goal object.
agents array can safely include the agent(s) affected by the goal—an agent pursuing this goal will ignore itself in the array. Therefore, you can use a single goal created with this method to cause an entire group of agents to mutually stay near one another.
max parameter determines how close to one another agents need to be in order for them to form a group. Changing the
max parameter determines how tightly an agent will turn to maintain cohesion in the group.
You can combine separation, alignment, and cohesion goals to produce “flocking” behaviors in which a group of agents move together.