03 Player Weapon

In this tutorial we’ll set up the player’s weapon.

We need to set up a weapon for our player attacks – Ellen attacks with a staff, which we’ll spawn during attacks using an equipment viewer on Ellen’s prefab.

You can learn more about equipment in this documentation.

We’ll set up:

  • a game state to handle showing or hiding the staff
  • equipment (also item types and equipment slots)
  • the player’s start equipment
  • components on the player and equipment prefabs

Let’s get to it.

Game State #

First, we’ll set up a game state that manages showing or hiding the weapon. Schematics animating the attacks will activate or deactivate the state, the equipment viewer uses the state as condition for showing the equipment.

Navigate to Game > Game States, we’ll add a new game state.

  • Name
    Set to Show Staff.
  • Initial State
    Disable this setting.

That’s it for the new game state.

Item Types #

Navigate to Inventory > Item Types, we’ll change the Default type and add an additional type.

0: Useables #

We’ll use this item type for the grenade and potion items.

  • Name
    Set to Useables.

Item Type Settings #

We need to set the damage type – this handles amations for damage or evade when items of this type are used.

The Default damage type is already set up to use the (also default) Damage animation type.

  • Damage Type
    Select Default.

1: Weapons #

Copy the Useables type.

  • Name
    Set to Weapons.

Equipment Slots #

Equipment slots are used to equip equipment on a combatant.

Navigate to Inventory > Equipment Slots. The default setup of a new project already has multiple equipment slots set up – we’ll only use the Weapon equipment slot.

Feel free to remove the other equipment slots, or keep them – we don’t need to make any other changes here.

Equipment #

Navigate to Inventory > Equipment, we’ll change the Default equipment and make Ellen’s staff out of it.

  • Name
    Set to Staff.

Item Settings #

  • Item Type
    Select Weapons.

Prefab Settings #

We only need to set up the viewer prefab, i.e. the prefab that’ll be used by Equipment Viewer components to show the weapon on the combatant.

  • Viewer Prefab
    Select Staff Variant.
    The prefab can be found in Assets/Tutorial Assets/Prefabs/Weapons/.

Equipment Settings > Equipment Slot Set 0 #

We’ll use the Deault slot set template, which we’ll set up right after this.

  • Slot Set Type
    Select Template.
  • Template
    Select Default.

Equipment Slot Set Template #

Either click on the Edit button beside the Template selection or navigate to Templates > Equipment Slot Set Templates and select the Default template.

  • Name
    Set to Weapon.

Equipable On #

Click on Add Equipment Slot.

  • Equipable On
    Select Weapon.

Player Start Equipment #

Navigate to Combatants > Combatants and select Ellen.

We’ll now add the start equipment (i.e. the staff).

Inventory & Equipment > Start Equipment #

We only need to set the start equipment and don’t have to take care about which equipment slots or equipment are available for the combatant.

The default setup in a new project adds all equipment lots to combatants and allows all equipment.

Click on Add Start Equipment.

Click on Add Equipment Slot.

  • Equipment Slot
    Select Weapon.
  • Equipment
    Select Staff.

Save Changes #

That’s it for the setup in the editor.

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

Updating the Player Prefab #

Open the Ellen Variant prefab for editing – you can find it in Assets/Tutorial Assets/Prefabs/Combatants/.

We’ll add a Damage Zone component (to allow the player to take damage from enemy Damage Dealer components), a Radius component (used for distance calculations) and an Equipment Viewer to show the staff.

Add Damage Zone #

Add a Damage Zone component to the prefab’s root using the component menu.

The default setup is already correct for us.

Add Radius #

Add a Radius component to the prefab’s root using the component menu.

It should automatically set the radius according to the added colliders.

  • Radius
    Select Value > Value.
  • Value
    Set to 0.4.

Add Equipment Viewer #

We need to add the Equipment Viewer component to the Ellen_Left_Hand_Attach child object:

Select the child object and use the component menu to add an Equipment Viewer component.

  • Equipment Slot
    Select Weapon.

Display Conditions #

Click on Add Condition.

  • Condition Type
    Select Game State.

Click on Add Game State.

  • Condition Type
    Select Game State.
  • Game State
    Select Show Staff.
  • Check State
    Select Active.

That’s it for Ellen’s prefab – save the changes.

Updating the Staff Prefab #

Open the Staff Variant prefab for editing – you can find it in Assets/Tutorial Assets/Prefabs/Weapons/.

As you can see, it has a larger Box Collider (used as trigger) added to it. This is what’ll be used to hit enemies (i.e. their Damage Zone components).

We only need to add a Damage Dealer component to it and set it up.

Add Damage Dealer #

Add a Damage Dealer component to the prefab’s root using the component menu.

  • Start Type
    Select Trigger Enter.
    Damage zones on game objects entering the trigger will cause damage to them.
  • Damage Zone From Children
    Enable this setting.
    Child objects of the game object entering the trigger will be searched for damage zones.
  • Damage Zone From Parent
    Enable this setting.
    Parent objects of the game object entering the trigger will be searched for damage zones.
  • One Time Damage
    Enable this setting.
    A combatant will only be damaged once by this damage dealer.
    This is only while the damage dealer is active – when it’s deactivated it’ll reset all targets and can damage the same target again.

Activation Settings #

Damage dealers can only deal damage when they’re activated (learn more about this in this documentation).

We’ll make use Activation Tags on the damage dealer and abilities to do this – if an ability uses a matching tag, the damage dealer can be activated by it.

  • Field
    Enable this setting.
    The damage dealer can be activated outside of battles.
  • All Battle Systems
    Enable this setting.
    The damage dealer can be activated in all battle systems.

Click on Add Activation Tag.

  • Activation Tag
    Set to weapon.

And that’s it for the staff prefab – save the changes.

 

Next, we’ll set up the player attacks.