Class

GKBehavior

A set of goals that together influence the movement of an agent.

Declaration

@interface GKBehavior : NSObject

Overview

By combining multiple goals (GKGoal objects) you can create complex behavior, such as groups of agents (GKAgent objects) that move together naturally. To assign a set of goals to an agent, use its behavior property.

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

Topics

Creating a Behavior

+ behaviorWithGoal:weight:

Creates a behavior with a single goal.

+ behaviorWithGoals:

Creates a behavior with the specified goals.

+ behaviorWithGoals:andWeights:

Creates a behavior with the specified goals and weights.

+ behaviorWithWeightedGoals:

Creates a behavior with the specified mapping of goals to their weights.

Managing a Behavior’s Set of Goals

- setWeight:forGoal:

Sets the weight for the specified goal’s influence on agents, adding that goal to the behavior if not already present.

- weightForGoal:

Returns the weight for the specified goal’s influence on agents.

- removeGoal:

Removes the specified goal from the behavior.

- removeAllGoals

Removes all goals from the behavior.

goalCount

The number of goals in the behavior.

Working with Goals Using Subscript Syntax

- objectForKeyedSubscript:

Returns the weight associated with the goal specified by subscript syntax.

- setObject:forKeyedSubscript:

Sets the weight for the goal specified by subscript syntax.

- objectAtIndexedSubscript:

Returns the goal at the specified index in the behavior’s list of goals.

Relationships

Inherits From

See Also

Agents, Goals, and Behaviors

GKAgent

A component that moves a game entity according to a set of goals and realistic constraints.

GKAgent2D

An agent that operates in a two-dimensional space.

GKAgent3D

An agent that operates in a three-dimensional space.

GKGoal

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

GKCompositeBehavior

A set of behaviors, each of which is a set of goals, that together influence the movement of an agent.

GKPath

A polygonal path that can be followed by an agent.

GKAgentDelegate

Implement this protocol to synchronize the state of an agent with its visual representation in your game.