AI line of sight

Human beings employ five distinct senses to interact with the environment. One of these, vision, is its own branch of Computer Science entitled Computer Vision. In this example, we implement basic vision testing in a Box2D environment using a Ray Cast to see if there is another object in-between the player and an enemy AI actor.

AI line of sight

Getting ready

Please refer to the project RecipeCollection03 for full working code of this recipe.

How to do it...

Execute the following code:

class RayCastAnyCallback : public b2RayCastCallback { public: RayCastAnyCallback() { m_hit = false; } float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point, const ...

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.