O'Reilly logo

jMonkeyEngine 3.0 Cookbook by Rickard Edén

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

Creating a reusable AI control class

In this recipe, we will create a control that is going to steer an AI character. Using Control to do this is beneficial since it can add the AI functionality and be used together with other Controls in the game. We can use GameCharacterControl from Chapter 2, Cameras and Game Controls for both the player and AI characters by adding AIControl to its spatial. To get a quick and visual result, we'll apply it to the bullet-based BetterCharacterControl class in this recipe.

How to do it...

We need to perform the following steps to get a basic, but functional attacking (or following) AI:

  1. We begin by creating a new class called AIControl, extending AbstractControl. The core of the recipe will be based around an enum ...

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