Book Image

iOS Game Programming Cookbook

Book Image

iOS Game Programming Cookbook

Overview of this book

Table of Contents (19 chapters)
iOS Game Programming Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Implementing the seek


To implement the seek behavior for our player, we will need a derive force that will redirect the agent toward a target position. In the seek behavior, our character will overshoot the target because the force applied on the player will be more, which will make the player overshoot the target and then return to the target. It will take a finite amount of time before coming to rest.

Getting ready

Seek behavior is something similar to the following screenshot:

The preceding image explains the algorithm that will be used to implement the seek behavior. In our case, we will need to seek to the target and have to follow the following algorithm:

Vector desiredVelocity = targetVector – player.locationVector;

desiredVelocity.normalize;

desiredVelocity *= player.maxSpeed;

return (desiredVelocity – agent.locationVector);

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...