August
31
2016

Learn how to add a turn based grid battle in this short gameplay tutorial series.

This is the 4th part of the gameplay tutorial series focused on turn based grid battles – you can find part 1 here. In this part we’ll set up the battle AI to allow enemy combatants to perform grid movement, add extra damage for attacking from the back as well as do some ability and battle event cleanup.

We’ll set up 3 battle AIs – one for moving into attack range toward enemies, one for moving into magic range toward enemies, and one for moving into support range toward allies.

Move Into Attack Range

First, we’ll set up a battle AI to move into attack range of a target, i.e. with a distance of 1 on the grid.

gameplay_22_grid_battles11

Battle AI Settings

  • Name
    Set to Move Into Attack Range.

Check Grid Distance

Add > Position > Check Grid Distance

We’ll use this step to check if an enemy of the user is already within attack range (grid distance of 1).

If an enemy is within attack range, this battle AI ends and the next AI of the combatant will be used, otherwise we’ll need to get the enemies that are not within attack range.

  • Found Targets
    Select Clear.
  • Target
    Select Enemy.
  • Check Type
    Select Is Equal.
  • Value Type (Check Value)
    Select Value.
  • Value (Check Value)
    Set to 1.

Check Grid Distance

Add > Position > Check Grid Distance

When no enemy was found within attack range, we’ll now get those who are outside of range.

This step is connected to the Failed slot of the previous Check Grid Distance step.

  • Found Targets
    Select Clear.
  • Target
    Select Enemy.
  • Check Type
    Select Is Greater.
  • Value Type (Check Value)
    Select Value.
  • Value (Check Value)
    Set to 1.

Grid Move

Add > Action > Grid Move

We’ll use this step to move the user toward the found target using the Grid Move command.

  • Move Type
    Select Move Toward Target.
  • Stop Distance
    Set to 1.
    We’ll stop at a cell next to the target.

That’s it for the attack range AI.

Move Into Magic Range

Next, we’ll set up a battle AI to move into magic range of a target, i.e. with a distance of 3 on the grid. Since the magic abilities have a use range with a shape mask only using cells in front of the user, we’ll also need to rotate the user to the target when a target is in range.

gameplay_22_grid_battles12

Battle AI Settings

  • Name
    Set to Move Into Magic Range.

Check Grid Distance

Add > Position > Check Grid Distance

We’ll use this step to check if an enemy of the user is already within magic range (grid distance of 3 or below).

If an enemy is within magic range, we’ll rotate to it, end the battle AI and the next AI of the combatant will be used, otherwise we’ll need to get the enemies that are not within magic range.

  • Found Targets
    Select Clear.
  • Target
    Select Enemy.
  • Check Type
    Select Is Less.
  • Value Type (Check Value)
    Select Value.
  • Value (Check Value)
    Set to 4.

Grid Rotate To Target

Add > Position > Grid Rotate To Target

There are targets within a distance of 3 cells, so we’ll use this step to rotate the user to face them.

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

  • Use Center
    Disable this setting.
    If multiple enemies where found, this would use the center of all enemies for the rotation.

Check Grid Distance

Add > Position > Check Grid Distance

When no enemy was found within magic range, we’ll now get those who are outside of range.

This step is connected to the Failed slot of the previous Check Grid Distance step.

  • Found Targets
    Select Clear.
  • Target
    Select Enemy.
  • Check Type
    Select Is Greater.
  • Value Type (Check Value)
    Select Value.
  • Value (Check Value)
    Set to 3.

Grid Move

Add > Action > Grid Move

We’ll use this step to move the user toward the found target using the Grid Move command.

  • Move Type
    Select Move Toward Target.
  • Stop Distance
    Set to 3.
    We’ll stop when coming within use range.

That’s it for the magic range AI.

Move Into Support Range

The battle AI for the support range will target allies of the user instead of enemies – we’ll want to move within 2 cells of the targets, since that’s the use range of our support abilities.

gameplay_22_grid_battles13

Battle AI Settings

  • Name
    Set to Move Into Support Range.

Check Grid Distance

Add > Position > Check Grid Distance

We’ll use this step to check if an ally of the user is already within support range (grid distance of 2).

If an ally is within attack range, this battle AI ends and the next AI of the combatant will be used, otherwise we’ll need to get the allies that are not within support range.

  • Found Targets
    Select Clear.
  • Target
    Select Ally.
  • Check Type
    Select Is Less.
  • Value Type (Check Value)
    Select Value.
  • Value (Check Value)
    Set to 3.

Check Grid Distance

Add > Position > Check Grid Distance

When no ally was found within support range, we’ll now get those who are outside of range.

This step is connected to the Failed slot of the previous Check Grid Distance step.

  • Found Targets
    Select Clear.
  • Target
    Select Ally.
  • Check Type
    Select Is Greater.
  • Value Type (Check Value)
    Select Value.
  • Value (Check Value)
    Set to 2.

Grid Move

Add > Action > Grid Move

We’ll use this step to move the user toward the found target using the Grid Move command.

  • Move Type
    Select Move Toward Target.
  • Stop Distance
    Set to 2.

And that’s it for the support range AI.

Updating Combatants

Next, we’ll need to update the battle AI settings of the enemy combatants. Navigate to Combatants > Combatants and change the following settings.

1: Evil Pants

Evil pants will use the attack range AI.

Battle Settings > Battle AI

Click on Add Battle AI to add a new battle AI.

  • Battle AI
    Select Move Into Attack Range.

Click on Move Up to to move the attack range AI above the Fighter AI.

2: Evil Caster

Evil caster will use the magic range AI.

Battle Settings > Battle AI

Click on Add Battle AI to add a new battle AI.

  • Battle AI
    Select Move Into Magic Range.

Click on Move Up to to move the magic range AI above the Magician AI.

3: Evil Supporter

Evil supporter will use the support range AI.

Battle Settings > Battle AI

Click on Add Battle AI to add a new battle AI.

  • Battle AI
    Select Move Into Support Range.

Click on Move Up to to move the support range AI above the Supporter AI.

Formula Update: Backstabbing

To get more tactical, we’ll add double damage when physically attacking someone from the back. Navitate to Game > Formulas, select the Physical Damage formula and add new steps at the end – as marked here:

gameplay_22_grid_battles14

Check Orientation

Add > Position > Check Orientation

We’ll use this step to check if the user is in the back of the target.

This step is connected to the Next slot of the last Value step (multiplying by the Level Factor).

  • Orientation
    Select Back.
  • From Target
    Enable this setting.

Value

Add > Value > Value

When the user is in the back of the target, we’ll multiply the formula result by 2.

This step is connected to the Success slot of the previous Check Orientation step.

  • Operator
    Select Multiply.
  • Value Type (Value)
    Select Value.
  • Value (Value)
    Set to 2.

We’ll create a small battle event next – don’t forget to save your changes by clicking on Save Settings.

Rotate To Target

Before we start cleaning up abilities and battle events, we need to set up a small battle event that will rotate the user to the target on the grid. We’ll need this soon, because we’re going to prevent the runToTarget event from happening in grid battles – without a new event rotating the user to the target this could result in attacks just swinging in the air, not facing the target. Not a game-breaker, but it doesn’t look that good.

This battle event is included in the Grid Prefabs, in case you don’t want to set it up yourself. Otherwise navigate to Events and create a new battle event.

gameplay_22_grid_battles15

Grid Direction Rotation

Add > Battle > Grid > Grid Direction Rotation

We’ll use this step to rotate the user to the target using grid directions.

  • Rotation
    Select Target.
    We’ll be rotating to the position of a target object.

Rotating Object

  • Object
    Select Actor.
  • Actor
    Select User.

Target Object

  • Object
    Select Actor.
  • Actor
    Select Target.

Fade Settings

  • Fade Rotation
    Disable this setting.

That’s it for the battle event – click on Save Event and e.g. save it as gridRotateToTarget.

Ability Cleanup

Since we’re now fighting on a grid, there are some things that need to be changed – for abilities, we’ll need to disable the battle events that move the combatant to and from the target in the Attack and Mug Attack abilities in grid battles, as well as add the new battle event we just set up.

0: Attack, 1: Mug Attack

We need to change 1 setting in Battle Event 0 and Battle Event 2 in the Animation Settings.

Battle Event 0 (runToTarget), Battle Event 2 (runToBase)

  • Grid Battles
    Select No.
    The battle events wont be used in battles using a battle grid.

The other events are set to Ignore grid battles, i.e. they’ll be used regardless of a battle grid being used or not.

Now, click on Add Animation to add a new battle event and change it’s settings.

  • Battle Event
    Select gridRotateToTarget.
  • Chance
    Set to 100.
  • Field
    Disable this setting.
  • Turn Based, Active Time, Real Time, Phase
    Enable these settings.
  • Grid Battles
    Select Yes.

Move the gridRotateToTarget battle event above the attack battle event by using the Move Up button.

That’s it for the settings – don’t forget to save your changes by clicking on Save Settings.

Battle Event Cleanup

Finally, we need to disable battle events to reset looking angles, since that would counteract the turn end orientation selections.

escape

Since we’re not using the runToBase battle event in grid battles, we only need to update the escape battle event. Navigate to Events and open the escape event by clicking on Open Battle Event and selecting it.

Event Settings

  • Reset Look Angles
    Disable this setting.

Testing

The basic grid battles are now ready and completely set up. Open the main menu scene (0 Main Menu), press play and fight on the grid!

gameplay_22_grid_battles16

But that’s not all you can do in grid battles – we’ll add some advanced gameplay mechanics in the next tutorials.

The next grid battles tutorial will add cell targeting abilities.