12 Potion

In this tutorial we’ll set up a healing potion for the player.

This time we’re setting up an item – it’ll heal 50 HP when used.

We’ll set up:

  • potion schematic
  • potion item
  • update the control map
  • add some potions to the player’s start inventory

Let’s get to it!

Potion Schematic #

Using the potion will be pretty simple, we’ll spawn a particle effect prefab, play an animation, wait and calculate the item’s outcome.

Navigate to Schematics and start working on a new schematic.

Settings #

We’ll block the player controls while using the potion, i.e. the movement input doesn’t rotate the combatant’s game object (it wouldn’t move in any case, since we’re using root motion for that).

  • Block Player Control
    Enable this setting.

Prefabs #

We also add the particle effect prefab.

Click on Add Prefab Resource.

  • Auto Destroy After Time
    Enable this setting.
  • Time
    Set to 3.
  • Prefab
    Select the Respawn prefab.
    You can find it in Assets/Tutorial Assets/EffectExamples/Misc Effects/Prefabs/.

Spawn Prefab #

Add Node > Game Object > Prefab > Spawn Prefab

We immediately spawn the prefab.

  • Prefab
    Select Prefab 0.
  • Target Type
    Select Object.
  • Object (Target Object)
    Select Machine Object.
  • Offset
    Set to X=0, Y=1, Z=0.

Play Sound #

Add Node > Audio > Audio > Play Sound

  • Object (Play On)
    Select Machin Object.
  • Audio Clip Asset
    Select zap2g.
  • Play One Shot
    Enable this setting.
  • Set Pitch
    Enable this setting.
  • Random Pitch
    Enable this setting.
  • Pitch
    Set to 0.8.
  • Pitch 2
    Set to 1.2.

Combatant Animation #

Add Node > Animation > Combatant > Combatant Animation

We’ll play the healing animation type – but this time we don’t wait.

  • Object
    Select Machine Object.
  • Animation Type
    Select Healing.

Wait #

Add Node > Base > Wait

We’ll wait for a second.

  • Time
    Select Value > Value.
    Set the value to 1.

Calculate Action #

Add Node > Battle > Action Outcome > Calculate Action

The item’s outcome will be calculated at this point, i.e. the user is healed now.

No further setup needed here.

Wait #

And we wait for another second, so just copy the previous Wait node.

And that’s it for the schematic. Click on Save Schematic to save it, e.g. as Potion.

Potion Item #

Next, we’ll set up the potion itself. It’ll heal 50 HP, is used on the user itself (i.e. no target selection) and has a reuse time of 10 seconds.

Navigate to Inventory > Items and change the Default item.

  • Name
    Set to Potion.
  • Sprite (Icon)
    Select icons_54.

Click on the Find TMP Tag button to get the icon’s tag for displaying it in texts (via text codes). This uses TextMesh Pro’s sprite asset setup.

Item Settings #

  • Item Type
    Select Useables.

Use Settings #

  • Useable In
    Select Both.

Battle Settings > Reuse Settings #

We’ll set up a reuse time of 10 seconds.

  • Own Reuse Time
    Enable this setting.

Click on Add Reuse Time.

  • Reuse Type
    Select Time.
  • Reuse After
    Select Value > Value.
    Set the value to 10.

Target Selection Settings #

The item should only be used on the user itself.

  • Target Type
    Select Self.

Target Settings > Target Changes #

Click on Add Target Change.

Click on Add Status Change.

  • Change Type
    Select Status Value.
  • Status Value
    Select HP.
  • Operator
    Select Add.
  • Change Value
    Select Value > Value.
    Set the value to 50.

Battle Animation #

Click on Add Battle Animation.

  • Schematic Asset
    Select Potion.

Updating the Control Map #

We’ll now update the control map.

Navigate to Base/Control > Control Maps and select the Default control map.

Control Key 2 #

Click on Add Control Key.

Input Settings #

  • Input Key
    Select Potion.

Action Settings #

  • Type
    Select Action.
  • Action
    Select Item.
  • Item
    Select Potion.

Conditions #

  • During Target Selection
    Disable this setting.

Updating Ellen #

And finally, we add a few potions to Ellen’s start inventory.

Navigate to Combatants > Combatants and select Ellen.

Inventory & Equipment > Start Inventory #

Click on Add Item.

  • Type
    Select Item.
  • Item
    Select Potion.
  • Quantity
    Select Value > Value.
    Set the value to 10.

Save Changes #

And that’s it!

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

Testing #

Hit play and use a potion (or get hit a few time first).

Remember, the potion key is Q.

And it’s working.

 

Next, we’ll add grenades!