Game Development Reference
In-Depth Information
How to do it
Now we will start again on the project to implement the seek behaviors. Now, follow the
steps below to implement the seek behavior:
1. Open the Player.m file and add the enum function on the top, after the import
statements:
typedef enum : NSUInteger {
Seek,
Arrive,
Flee,
Wander,
Evade
} SteeringBehaviorType;
2. Then, add the following code after your interface:
@property (assign) SteeringBehaviorType behaviourType;
@property (assign) CGPoint target;
The enum holds the behavior we want to implement. Whenever we add any beha-
vior, we will have to add it to this enum .
The target property will hold the location where we want the player to seek and
behaviourType will tell us which behavior we want to implement.
3. Now, to implement the seek, add the following function:
- (void) seek:(CGPoint )target
deltaTime:(float)deltaTime {
// Work out the direction to this position
GLKVector2 myPosition =
GLKVector2Make(self.position.x, self.position.y);
GLKVector2 targetPosition =
GLKVector2Make(target.x, target.y);
GLKVector2 offset =
GLKVector2Subtract(targetPosition, myPosition);
Search WWH ::




Custom Search