Chapter 4. Creating an Enemy AI

Pretty much every game has bad guys and it is no different in GAS. In this chapter, we will create our very own enemy artificial intelligence (AI) that can shoot at the player. Here is what you will learn:

  • How to register a new AI class
  • How to make the AI detect the player and not move
  • How to make the AI shoot the player

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.202.103