Firing projectiles at moving targets
For AI actors to interact with their environment realistically, they must make calculations that human players make naturally. One common interaction involves firing a projectile at a moving target.
Getting ready
Please refer to the project RecipeCollection03 for full working code of this recipe.
How to do it...
Execute the following code:
@implementation Ch7_ProjectileAiming -(void) step: (ccTime) dt { [super step:dt]; /* CODE OMITTED */ //Firing projectiles fireCount += dt; if(fireCount > 1.0f){ fireCount = 0; [self fireMissiles]; } } /* Each enemy fires a missile object */ -(void) fireMissiles { for(int i=0; i<enemies.count; ...
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.