GKGoal
An influence that motivates the movement of one or more agents.
Declaration
class GKGoalOverview
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
init(toAvoid:maxPredictionTime:)init(toAvoid:maxPredictionTime:)init(toInterceptAgent:maxPredictionTime:)
Creating Goals for Flocking Behavior
init(toSeparateFrom:maxDistance:maxAngle:)init(toAlignWith:maxDistance:maxAngle:)init(toCohereWith:maxDistance:maxAngle:)
Creating Goals for Path-Following Behavior
Initializers
init(toAlignWithAgents:maxDistance:maxAngle:)init(toAvoidAgents:maxPredictionTime:)init(toAvoidObstacles:maxPredictionTime:)init(toCohereWithAgents:maxDistance:maxAngle:)init(toFollowPath:maxPredictionTime:forward:)init(toSeparateFromAgents:maxDistance:maxAngle:)init(toStayOnPath:maxPredictionTime:)