18 Item Drops

In this tutorial we’ll set up item drops from killed enemies.

We’ve only got a limited supply of potions and grenades, so let’s have our enemies drop them for us.

We’ll let them drop a grenade (10%) or potion (5%) on the spot they died, picking it up by moving over it (i.e. Trigger Enter). The item will be displayed by a rotating sprite.

We’ll set up:

  • schematic to rotate the sprite
  • prefabs for items
  • update the items
  • item drop settings
  • loot
  • update combatants (adding loot)
  • update to the battle system

Let’s get to it!

Pickup Rotation Schematic #

This’ll be very simple – the schematic is executed by a Tick Machine, executing it each frame.

Navigate to Schematics and start working on a new schematic.

Rotate #

Add Node > Movement > Rotation > Rotate

This node is doing a one time rotation change and is meant to be used in tick machines, i.e. regularly updated.

We’ll use it to rotate the game object by 90° per second.

  • Object (Rotating Object)
    Select Machine Object.
  • Rotate Component
    Select Transform.
    You can also leave it on Auto, since there is no other relevant component on the game object we’ll set up.
  • Value (Rotation Change)
    Set to X=0, Y=1, Z=0.
    This’ll let it rotate on the Y-axis.
  • Rotation Speed
    Select Value > Value.
    Set the value to 90.
  • Use Delta Time
    Enable this setting.
    This will let it rotate based on the framerate (delta time), i.e. the 90 rotation speed is per second.

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

You can close the editor for now.

Pickup Prefabs #

Next, we’ll set up prefabs for our item pickups – from scratch!

Drag the icons_54 sprite into the scene, you can find it in Assets/Tutorial Assets/Icons/ as a sub-asset of the icons sprite.

We’ll add a Sphere Collider and a Tick Machine to it.

Sphere Collider #

Add a Sphere Collider component using the component menu.

  • Is Trigger
    Enable this setting.

Tick Machine #

Add a Tick Machine component using the component menu.

Start Settings #

  • Update
    Enable this setting.
    This machine will start each frame.

Machine Execution Settings #

  • Schematic Asset
    Select the PickupRotation schematic.

Create Prefab #

And that’s it – create a prefab out of the game object and e.g. name it PotionPickup.

Grenade Variant #

Now, with the game object (now linked to the prefab) still in the scene, we’ll change the used sprite.

Make sure you have the scene’s game object selected, not the prefab you created.

Sprite Renderer #

  • Sprite
    Select icons_267.

Create Prefab #

And that’s it – create a new prefab variant (or original prefab) out of the game object and e.g. name it GrenadePickup.

You can now remove the game object from the scene.

Updating Items #

Open the editor and navigate to Inventory > Items, we’ll now set up the prefabs we’ve created to be used by the items.

0: Potion #

Item Settings > Prefab Settings #

  • Own Prefab
    Enable this setting.
  • Item Prefab
    Select PotionPickup.
  • Spawn Offset
    Set to X=0, Y=0.5, Z=0.

1: Grenade #

Item Settings > Prefab Settings #

  • Own Prefab
    Enable this setting.
  • Item Prefab
    Select GrenadePickup.
  • Spawn Offset
    Set to X=0, Y=0.5, Z=0.

Inventory Settings #

Next, we’ll set up how items are dropped into the world (e.g. by our enemies) and how they’re collected.

Navigate to Inventory > Inventory Settings.

Drop Item Settings #

These settings handle how items are dropped into the game world (e.g. from enemies dropping items on death).

  • Drop On Ground
    Disable this setting.
    We’ll just spawn them using the position of the combatant without trying to find the ground.
    No need for that in our setup.

We’ll also not use a random offset when spawning, directly spawning at the combatant’s position.

  • Offset X
    Set to X=0, Y=0.
  • Offset Y
    Set to X=0, Y=0.
  • Offset Z
    Set to X=0, Y=0.

Start Settings > Trigger #

We’ll use Trigger Enter to collect the dropped items – i.e. when the player runs into the item.

  • Trigger Enter
    Enable this setting.

Despawn Settings #

We’ll also remove dropped items after 30 seconds of not being collected.

  • Despawn Battle Drops
    Enable this setting.
  • Despawn Time
    Select Value > Value.
    Set the value to 30.

Item Collection #

We’re also going to disable showing a collection dialogue, but enable playing a sound when collecting.

After Collection (Ok) #

  • Play Sound
    Enable this setting.
  • Audio Clip
    Select swoosh03.

Collection Dialogue #

  • Show Dialogue
    Disable this setting.

Loot #

Next, we’ll set up the loot table that’ll handle if and which item is dropped.

Navigate to Combatants > Loot and select the Default loot.

Click on Add Loot Table.

Loot Table 0 > Loot Settings #

  • Get Random
    Enable this setting.
  • Use Chance Selection
    Enable this setting.
    This’ll use the chance settings of each item to select which is dropped.
    E.g. first item has 10% chance, second item 5% chance results in a total 15% chance of an item being dropped.

Click on Add Item.

  • Type
    Select Item.
  • Item
    Select Potion.
  • Quantity
    Select Value > Value.
    Set the value to 1.
  • Chance
    Select Value > Value.
    Set the value to 5.

Copy Item 0.

  • Item
    Select Grenade.
  • Chance
    Select Value > Value.
    Set the value to 10.

Updating Combatants #

We’ll use the loot as the default loot for all combatants, i.e. all will have the same item drops.

Navigate to Combatants > Combatants > General Settings.

Inventory & Equipment > Default Loot Settings #

  • Loot Origin
    Select Loot.

Click on Add Loot.

  • Loot
    Select Default.

Updating Real Time Battle System #

And finally, we need to update how battle gains are collected in our battle system.

Navigate to Battles > Battle System and select the Real Time battle system.

Battle System Settings > Battle Gains Collection #

  • Own Gains Collection
    Enable this setting.
  • Collect Immediately
    Enable this setting.
  • Show Gains
    Disable this setting.
  • Collect Loot
    Enable this setting.
  • Drop Items
    Enable this setting.

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 kill some enemies.

Lucky, we got some loot!

One Last Thing #

With the battle taking place all over the scene, you’ll notice that flying texts for damages far away from the player are popping up. Let’s fix that!

Navigate to UI > UI Settings, we’ll limit the display range for flying texts.

Flying Text Settings #

  • Limit Display Range
    Enable this setting.
  • Range
    Select Value > Value.
    Set the value to 20.

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


That’s it – we’re done with the 3D Action RPG tutorials. Allow me to say some final words in the next and final part of this tutorial series.