Processing AI waypoints
One of the most basic AI processes involves moving an AI actor around in a physical environment. To do this, we will create a queue of waypoints. Each waypoint represents the next position we want our actor to move to.
Getting ready
Please refer to the project RecipeCollection03 for full working code of this recipe.
How to do it...
Execute the following code:
#import "GameWaypoint.h" @interface GameActor : GameObject { NSMutableArray *waypoints; float runSpeed; } @end @implementation GameActor -(void) processWaypoints { bool removeFirstWaypoint = NO; //The actor's position onscreen CGPoint worldPosition = CGPointMake(self.body->GetPosition().x ...
Get Cocos2d for iPhone 1 Game Development Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.