Contents

GKGoal

An influence that motivates the movement of one or more agents.

Declaration

class GKGoal

Overview

Goals can motivate agents (GKAgent objects) to actions such as moving toward a target, following a path, or staying aligned with a group of other agents. To give an agent one or more goals, combine those goals in a GKBehavior object (which includes weights for the relative influence of each goal) and assign that object to the agent’s behavior property.

Each time an agent’s update(deltaTime:) method runs, the agent evaluates each goal in its behavior to find the change in direction and speed necessary to move toward fulfilling that goal (within the limits of the time delta and the agent’s maximum speed and turn rate). It then combines the effects from all the goals in its behavior, using the weights in the behavior to modulate the influence of each goal, to produce a total change in its direction and speed.

To learn more about using goals and agents, see Agents, Goals, and Behaviors in GameplayKit Programming Guide.

Topics

Creating Goals for General Movement Behavior

Creating Goals for Avoidance and Interception Behavior

Creating Goals for Flocking Behavior

Creating Goals for Path-Following Behavior

Initializers

See Also

Agents, Goals, and Behaviors