10 Battle AI

In this tutorial we’ll set up grid movement in the battle AI.

The status system setup tutorials already set up most of the battle AI, we’ll extend it by adding grid movement.

Well set up:

  • update the Provoked battle AI
  • make a new variant of the Provoked battle AI for ranged combatants
  • update the Heal <50% HP battle AI
  • update the combatant’s battle AI setup

Let’s get to it.

Updating Provoked Battle AI #

We’ll start with updating the Provoked battle AI. If you remember from the status system setup tutorials, this battle AI will check if the player (i.e. the enemy of the user) has the Provoke status effect added, making it a primary target.

We’ll extend on that and also move to the target using a Grid Move action – and if no provoking enemy was found, we’ll move to the nearest enemy.

Navigate to Battles > Battle AI and selected Provoked.

Check Grid Distance #

Add Node > Position > Check Grid Distance

We’ll limit being provoked to a certain distance on the grid, i.e. we’ll check the grid distance to the found target (i.e. the combatant with Provoke status effect).

This node is connected to the Success slot of the Check Status node.

  • Found Targets
    Select Check.
    We check the already found targets.
  • Target
    Select None.
    We don’t check additional targets.
  • Check Type
    Select Is Less Equal.
  • Check Value
    Select Value > Value.
    Set the value to 10.

Grid Move #

Add Node > Action > Grid Move

This node selects a path to a target (cell) and uses the grid move action. We’ll move to the found target.

This node is connected to the Success slot of the Check Grid Distance node.

  • Move Type
    Select Move Toward Target.
  • Target Cell
    Select Nearest.

Target Cell Settings #

These settings define which cells around the target are valid to move to – we’ll use a battle range template for this.

  • Range Type
    Select Battle Range Template.
  • Battle Range Template
    Select Range 1.

Check Status #

Add Node > Combatant > Check Status

In case we don’t have a provoking enemy (or not in range), we’ll find an alive enemy before selecting the nearest of them.

This node is connected to the Failed slots of the first Check Status node and the Check Grid Distance node.

  • Found Targets
    Select Clear.
  • Target
    Select Enemy.

Click on Add Status Condition.

  • Condition Type
    Select Status.
  • Status Needed
    Select Death.
  • Is Dead
    Disable this setting.

Get Nearest #

Add Node > Position > Get Nearest

We’ll now selected the nearest found target (i.e. the nearest alive enemy).

This node is connected to the Success slot of the previous Check Status node and it’s Next slot connects to the Grid Move node.

  • Found Targets
    Select Check.
  • Target
    Select None.
  • Use Grid Distance
    Enable this setting.

Provoked Ranged Battle AI #

Copy the Provoked battle AI, we’ll change it a bit for ranged combatants (e.g. the ranger, wizard and cleric) to not move directly to the target and stay a bit away from it.

Battle AI Settings #

  • Name
    Set to Provoked Ranged.

Grid Move #

We’ll use a different battle range tempalte and also prevent using cells directly neighboring the target.

Target Cell Settings #

  • Battle Range Template
    Select Range 5.
  • Use Enemy Distance
    Enable this setting.
  • Minimum Distance
    Set to 2.

Updating Heal <50% HP Battle AI #

Select the Heal <50% HP battle AI, we’ll move toward the found ally to get in range to help them.

Grid Move #

Add Node > Action > Grid Move

This node is connected to the Success slot of the Check Status node and it’s Success slot connects to the Ability node (i.e. add the node between Check Status and Ability nodes).

  • Move Type
    Select Move Toward Target.
  • Target Cell
    Select Nearest.

Target Cell Settings #

The healing ability will have a use range of 5 (we’ll set that up in the next tutorial), so we need to move within the same range to the target (ally).

  • Range Type
    Select Battle Range Template.
  • Battle Range Template
    Select Range 5.

Updating Combatants #

With our battle AI ready, we can now update our combatants. The default battle AI is already set up and used by all of them (using Provoked, etc.) – we only need to update the ranged combatants, i.e. the RangerWizard and Cleric. The cleric also uses the updated heal battle AI.

Navigate to Combatants > Combatants and select the Ranger.

2: Ranger #

The ranger pretty much uses the default battle AI setup, but replaces provoked with the ranged variant.

Battle Settings > Battle AI #

  • Replace Default
    Enable this setting.

Click on Add Battle AI.

  • Battle AI
    Select Provoked Ranged.

Click on Add Battle AI.

  • Battle AI
    Select Random Ability 25%.

Click on Add Battle AI.

  • Battle AI
    Select Base Attack.

Click on Add Battle AI.

  • Battle AI
    Select Do Nothing.

3: Wizard #

The wizard will use an ability 50% of the time, anything more would probably obliterate the player.

Battle Settings > Battle AI #

  • Replace Default
    Enable this setting.

Click on Add Battle AI.

  • Battle AI
    Select Provoked Ranged.

Click on Add Battle AI.

  • Battle AI
    Select Random Ability 50%.

Click on Add Battle AI.

  • Battle AI
    Select Base Attack.

Click on Add Battle AI.

  • Battle AI
    Select Do Nothing.

4: Cleric #

The cleric will prioritize healing allies before getting provoked and attacking.

Battle Settings > Battle AI #

  • Replace Default
    Enable this setting.

Click on Add Battle AI.

  • Battle AI
    Select Heal <50% HP.

Click on Add Battle AI.

  • Battle AI
    Select Provoked Ranged.

Click on Add Battle AI.

  • Battle AI
    Select Random Ability 50%.

Click on Add Battle AI.

  • Battle AI
    Select Base Attack.

Click on Add Battle AI.

  • Battle AI
    Select Do Nothing.

Save Changes #

And that’s it for the battle AI setup.

Don’t forget to save your changes by clicking on Save Settings at the bottom of the editor.

Testing #

Hit play in the Forest Battle 1 scene – move a bit and end your phase.

The enemy will now also move on the grid.

 

Next, we’ll update the abilities to use use ranges and affect ranges.