CRYENGINE Game Development Blueprints
上QQ阅读APP看书,第一时间看更新

Registering a new AI class

At the heart of every character in CRYENGINE is the IActor interface. It provides the mechanism for objects to have AI. When we refer to a player or an AI, we are really referring to something called an actor. An actor is responsible for containing and managing all the logic that will be used to bring an object to life. This can range from being an animal companion, an AI character, or any other game object whose purpose is to represent living objects. Since GAS is a very simple side-scroller, we will not be using CRYENGINE's AI system. However, we will use CRYENGINE's IActor interface since our character is a living object. There is not much difference between our player and the AI; the only difference is how they shoot and who they shoot at. This allows us to reuse the CPlayer class for our AI, and simply register it under a different class name.

Open the CGASGame.cpp file and navigate to the RegisterGameObjects() method. Re-register the CPlayer class under the name AI. It should look like this:

//Registers The AI.
REGISTER_FACTORY( m_pGameFramework, "AI", CPlayer, true );

Notice that we reuse the CPlayer implementation and just register it under a different class name AI. This will create another entity class called AI that uses the exact same code as the CPlayer class.