---
title: GKGoal
framework: gameplaykit
role: symbol
role_heading: Class
path: gameplaykit/gkgoal
---

# GKGoal

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

## Declaration

```swift
class GKGoal
```

## Overview

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

- [init(toSeekAgent:)](gameplaykit/gkgoal/init(toseekagent:).md)
- [init(toFleeAgent:)](gameplaykit/gkgoal/init(tofleeagent:).md)
- [init(toReachTargetSpeed:)](gameplaykit/gkgoal/init(toreachtargetspeed:).md)
- [init(toWander:)](gameplaykit/gkgoal/init(towander:).md)

### Creating Goals for Avoidance and Interception Behavior

- [init(toAvoid:maxPredictionTime:)](gameplaykit/gkgoal/init(toavoid:maxpredictiontime:)-96a0i.md)
- [init(toAvoid:maxPredictionTime:)](gameplaykit/gkgoal/init(toavoid:maxpredictiontime:)-7oslq.md)
- [init(toInterceptAgent:maxPredictionTime:)](gameplaykit/gkgoal/init(tointerceptagent:maxpredictiontime:).md)

### Creating Goals for Flocking Behavior

- [init(toSeparateFrom:maxDistance:maxAngle:)](gameplaykit/gkgoal/init(toseparatefrom:maxdistance:maxangle:).md)
- [init(toAlignWith:maxDistance:maxAngle:)](gameplaykit/gkgoal/init(toalignwith:maxdistance:maxangle:).md)
- [init(toCohereWith:maxDistance:maxAngle:)](gameplaykit/gkgoal/init(tocoherewith:maxdistance:maxangle:).md)

### Creating Goals for Path-Following Behavior

- [init(toStayOn:maxPredictionTime:)](gameplaykit/gkgoal/init(tostayon:maxpredictiontime:).md)
- [init(toFollow:maxPredictionTime:forward:)](gameplaykit/gkgoal/init(tofollow:maxpredictiontime:forward:).md)

### Initializers

- [init(toAlignWithAgents:maxDistance:maxAngle:)](gameplaykit/gkgoal/init(toalignwithagents:maxdistance:maxangle:).md)
- [init(toAvoidAgents:maxPredictionTime:)](gameplaykit/gkgoal/init(toavoidagents:maxpredictiontime:).md)
- [init(toAvoidObstacles:maxPredictionTime:)](gameplaykit/gkgoal/init(toavoidobstacles:maxpredictiontime:).md)
- [init(toCohereWithAgents:maxDistance:maxAngle:)](gameplaykit/gkgoal/init(tocoherewithagents:maxdistance:maxangle:).md)
- [init(toFollowPath:maxPredictionTime:forward:)](gameplaykit/gkgoal/init(tofollowpath:maxpredictiontime:forward:).md)
- [init(toSeparateFromAgents:maxDistance:maxAngle:)](gameplaykit/gkgoal/init(toseparatefromagents:maxdistance:maxangle:).md)
- [init(toStayOnPath:maxPredictionTime:)](gameplaykit/gkgoal/init(tostayonpath:maxpredictiontime:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Agents, Goals, and Behaviors

- [GKAgent](gameplaykit/gkagent.md)
- [GKAgent2D](gameplaykit/gkagent2d.md)
- [GKAgent3D](gameplaykit/gkagent3d.md)
- [GKBehavior](gameplaykit/gkbehavior.md)
- [GKCompositeBehavior](gameplaykit/gkcompositebehavior.md)
- [GKPath](gameplaykit/gkpath.md)
- [GKAgentDelegate](gameplaykit/gkagentdelegate.md)
