O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A* pathfinding

A star pathfinding is used when you want the enemy AI to have an intelligent behavior in which given the location of the player, the enemy will be able to navigate through the map and get to the location of the player using the shortest distance.

To calculate the shortest path, we will find the cost of getting to the location of the player. This cost, called the F cost, is the total of the G cost and H cost. The G cost is the cost of moving from the starting point of the enemy to the current position of the object. The H cost is the cost of the moving from the current location to the destination, which is the location of the player.

From a position, the player can move up, down, left, or right, and for each movement, the cost is calculated. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required