[5SD033] Plane AI, States and Behaviour

20160208_111421.jpg
Above; flowchart describing briefly how the AI moves between states according to conditions.

This week has been dedicated to the planning and structuring of a simple AI and the various behaviours necessary to facilitate a basic enemy plane.

The underlying structure is a finite state machine, a set of coded behaviours that are switched when specified conditions are met.

The desired behaviour of the plane is based on the stealth elements of the game, requiring it to patrol certain routes until it finds a player upon which it will chase after and attack until the player either crashes or manages to shake the enemy off by employing stealth tactics(such as like flying into clouds). The plane then tries to search for the player at and around the last known location the player was seen. The plane should feel predictable enough that one can anticipate what it is currently doing and how it will react if the player is detected or lost from sight.

I decided on utilizing class hierarchy, making a class inherit functions from another, in order to switch states as a pointer to a class higher in the hierarchy is a valid pointer to any classes inherited by it. This allows each state to be created and switched to when conditions are met by deleting the previous state and allocating the pointer to the new one. The states are Patrol, Chase and Search, inheriting functions to handle state-specific behaviour, such as following the player and shooting while in Chase, moving along a designated path while in patrol or attempting to find a player that has eluded the plane.

States and the behaviours thereof:

  • Patrol: Chooses a designated or randomly allocated spot on the map by selecting a section of the map that does not contain too many enemies and picks a coordinate within it that section. The plane then proceeds to move between its starting position and the newly designated one a few laps, then the process is restarted.
  • Chase: If the player is within the planes detection radius it will speed up and follow, sticking to the player’s trail or rebounding away in a circle if it is about to crash into the player. Worth adding, but more difficult, is the same rebounding movement if the plane gets fired at or gets hit. If it gets close enough it will attempt to line up a salvo of gunfire.
  • Search: When the player succesfully gets away from the plane’s chase radius, it will attempt to find the player by checking what last location the player was spotted in and circling the area outwards, eventually giving up and moving on to patrol again.

 

About Erik Nord

2015 Programming