May
23
2015

Setting up the enemy machines.

In this tutorial we’ll set up the enemy game objects. We’ll add the schematics we created in the previous tutorial using different machines.

The setup for all 3 enemies (Zombunny, ZomBear and Hellephant) is the same (except for minimal differences). The following component setup can be repeated for all enemy prefabs, or you can just copy the components and paste them on the other enemies.

The enemy prefabs can be found at Assets/Tutorial Resources/Prefabs/. We’ll add the components directly to the prefabs.

Object Variables

First, we’ll set up the object variables of the enemies. Add an object variable component to the prefabs (e.g. using the component menu: Makinom > Scenes > Object Variables). Change the following settings.

  • Local Variables
    Enable this setting.
    The enemies can be spawned multiple times, so we don’t want them to share their variables.
  • Always Initialize
    Enable this setting.

Click on Add Variable to add an object variable.

  • Variable Key
    Set to health.
    Select the Value string type.
  • Type
    Select Int.
  • Operator
    Select Set.
  • Float Value
    Zombunny: Set to 100 (Value).
    ZomBear: Set to 100 (Value).
    Hellephant: Set to 300 (Value).

Copy the variable and change the following settings.

  • Variable Key
    Set to points.
  • Float Value
    Zombunny: Set to 10 (Value).
    ZomBear: Set to 10 (Value).
    Hellephant: Set to 50 (Value).

That’s it for the object variables.

Enemy Movement: Tick Machine

Next, we’ll add the EnemyMovement schematic using a tick machine.

Add the component to the enemy prefabs (e.g. using the component menu: Makinom > Machines > Tick Machine). Change the following settings.

Start Settings

  • Update
    Enable this setting.

Machine Execution Settings

  • Asset Type
    Select Schematic.
  • Schematic Asset
    Select EnemyMovement.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Enemy Attack: Trigger Machine

The enemy’s attack will be started while the player is within the enemy’s trigger.

Add a trigger machine component to the enemy prefabs (e.g. using the component menu: Makinom > Machines > Trigger Machine). Change the following settings.

Start Settings

  • Trigger Stay
    Enable this setting.

Machine Execution Settings

  • Asset Type
    Select Schematic.
  • Schematic Asset
    Select EnemyAttack.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Condition Settings

The attack should only start if the enemy’s and player’s health is above 0.

  • Check Variables
    Enable this setting.
  • Needed
    Select All.

Click on Add Variable to add a variable condition.

  • Variable Key
    Set to health.
    Use the Value string type.
  • Variable Origin
    Select Object.
  • Game Object
    Select User.
  • Is Valid
    Enable this setting.
  • Exists
    Enable this setting.
  • Type
    Select Int.
  • Check Type
    Select Is Greater.
  • Check Value
    Set to 0 (Value).

Copy the variable condition and change the following settings.

  • Game Object
    Select Player.

Local Start Variables

The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values, so all we need to do is adjust them to our needs. Make sure both variables are enabled.

  • damage
    Zombunny: Set to 10.
    ZomBear: Set to 15.
    Hellephant: Set to 30.
  • attackTimeout
    We can keep the default value of 0.5 on all enemy prefabs.

Take Damage: Tagged Machine

Now, we’ll add the TakeDamage schematic using a tagged machine that will be stared by the tag damage.

Add a tagged machine component to the enemy prefabs (e.g. using the component menu: Makinom > Machines > Tagged Machine). Change the following settings.

Start Settings

Click on Add Starting Tag to add a tag that can start this machine.

  • Starting Tag
    Set to damage.

Machine Execution Settings

  • Asset Type
    Select Schematic.
  • Schematic Asset
    Select TakeDamage.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Resource Overrides

Expand the Resource Overrides to change the used audio clip.

  • Override Audio Clips
    Enable this setting.

Click on Add Audio Clip to add an audio clip that will be used.

  • Audio Clip
    Zombunny: Select ZomBunny Hurt.
    ZomBear: Select ZomBear Hurt.
    Hellephant: Select Hellephant Hurt.
    The audio clips can be found at Assets/Tutorial Resources/Audio/Effects/.

Enemy Death: Tagged Machine

Finally, we’ll add the EnemyDeath schematic using a tagged machine started by the tag death.

Add a tagged machine component to the enemy prefabs (e.g. using the component menu: Makinom > Machines > Tagged Machine). Change the following settings.

Start Settings

Click on Add Starting Tag to add a tag that can start this machine.

  • Starting Tag
    Set to death.

Machine Execution Settings

  • Asset Type
    Select Schematic.
  • Schematic Asset
    Select EnemyDeath.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Resource Overrides

Expand the Resource Overrides to change the used audio clip.

  • Override Audio Clips
    Enable this setting.

Click on Add Audio Clip to add an audio clip that will be used.

  • Audio Clip
    Zombunny: Select ZomBunny Death.
    ZomBear: Select ZomBear Death.
    Hellephant: Select Hellephant Death.
    The audio clips can be found at Assets/Tutorial Resources/Audio/Effects/.

And that’s it for now. Since we added the components directly on the prefabs, we don’t need to apply the changes.

Testing

If you want to test your enemies, just drag them into the scene and click on Play. The enemis will move toward the player, if you shoot them, they’ll die once their health is gone. They aren’t yet able to damage the player, since we didn’t add the TakeDamage schematic to it yet – we’ll do this later.

The next tutorial will handle HUDs.