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 arrive


Arrive is similar to seek. The only difference between seek and arrive is that in arrive the player will stop at the target location. However, in seek, it overshoots the target location and then seeks again.

Getting ready

The technical definition of arrive is to reach the goal with zero velocity. The arrival behavior will remain the same as the seek behavior, the only difference is that it will not overshoot the target.

In this approach, when the player is outside the stopping radius, it will follow the maximum speed toward the target, while as soon as the player is inside the stopping radius, the desired velocity of the player will be ramped down to zero.

How to do it

Perform the following steps to implement the arrive behavior:

  1. Open the Player.m file, and add the following line of code in the end of the file:

    - (void) arrive:(CGPoint )target deltaTime:(float)deltaTime {
        
        // Work out the direction to this position
        GLKVector2 myPosition = GLKVector2Make(self.position...