Respawning AI

In this recipe, we will explore how you will be able to utilize the Territory and Wave systems along with a little bit of FlowGraph scripting to make your AI respawn after a couple of seconds of death.

Getting ready

  • Before we begin, you must have Sandbox 3 open
  • Then open My_Level.cry
  • Place down one Grunt within the level

How to do it...

Making a territory:

  1. From the RollupBar, open the Objects tab and click the Entity button.
  2. Open the AI folder and select AITerritory.
  3. Click down four points to surround the AI Grunt (double-click to finalize).

Placing the AI wave entity:

  1. From the RollupBar, open the Objects tab and click the Entity button.
  2. Open the AI folder and select AIWave.
  3. Place the AI wave entity close to the AITerritory.

Linking the territory to the wave:

  1. Select AITerritory1 and click the Pick button.
  2. Click AIWave1 to pick that entity as the target.

Giving the AI Grunt the territory and wave IDs:

  1. Select the Grunt.
  2. Under Entity Properties2, assign AITerritory1 as the territory and AIWave1 as the wave.

Creating a simple FlowGraph (FG) to respawn the Grunt:

  1. Right-click AIWave1 | Create Flow Graph.
  2. Click OK.
  3. Select AIWave1 from Viewport.
  4. In FG, right-click | Add Selected Entity.
  5. Select AITerritory1.
  6. In FG, right-click | Add Selected Entity.
  7. In FG, right-click | Add Node | Misc | Start.
  8. In FG, right-click | Add Node | Time | Delay.
  9. Copy and paste the Time:Delay node and set the Delay integer on the second node to 5 (seconds).
  10. Link (click-and-drag) Start output to In on Time:Delay 1 second.
  11. Link out from Time:Delay 1 to Enable on AITerritory1.
  12. Link Enabled from AITerritory1 to Enable on AIWave1.
  13. Link Dead from AIWave1 to In on Time:Delay 5.
  14. Link out from Time:Delay 5 to Spawn on AIWave1.
    How to do it...

How it works...

With the AI territories and wave system, we can link this into a flow graph to allow the AI within the territory and wave to respawn after five seconds of their death. Anything outside of the AI wave will not respawn.

There's more...

Here are some definitions for the AI territory and wave FlowGraph nodes that you should know about.

AI territory FlowGraph node properties

Input:

  • Disable: This disables the territory
  • Enable: This enables the territory
  • Kill: This kills all active AIs of this territory
  • Spawn: (Re-)Spawns AIs assigned to this territory (but not assigned to any wave)

Output:

  • ActiveCount: Outputs the number of currently active AIs assigned to this territory
  • Dead: Fires when all AIs assigned to this territory are dead (works also for respawned AIs)
  • Disabled: Fires when the territory gets disabled (it doesn't fire on level start, although all territories are disabled from start automatically)
  • Enabled: Fires when the territory gets enabled
  • Spawned: Fires when AIs are spawned via the spawn input (if the territory was disabled before, it gets enabled and the enabled output fires as well)

AI wave FlowGraph node properties

Input:

  • Disable: This disables the wave
  • Enable: This enables the wave
  • Kill: This kills all active AIs of this wave
  • Spawn: This (re-)spawns AIs assigned to this wave

Output:

  • ActiveCount: Outputs the number of currently active AIs assigned to this wave
  • Dead: Fires when all AIs assigned to this wave are dead (works also for respawned AIs)
  • Disabled: Fires when the wave gets disabled (it doesn't fire on level start, although, all waves are disabled from start automatically)
  • Enabled: Fires when the wave gets enabled
  • Spawned: Fires when AIs are spawned via the spawn input (if the wave was disabled before, it gets enabled and the enabled output fires as well)
..................Content has been hidden....................

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