Setting up the enemy machines.

In this tutorial we’ll set up the enemy game objects. We’ll add object variables and machine components using the schematics we created in the previous tutorial.

The setup for both enemies (enemy1 and enemy2) is the same (except for minimal differences). The following component setup can be repeated for both enemy prefabs, or you can just copy the components and paste them on the other enemy. The prefabs can be found at Assets/Tutorial Resources/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. This variable will store if the enemy is facing left or right.

  • Variable Key
    Set to facingRight.
    Select the Value string type.
  • Type
    Select Bool.
  • Bool Value
    Enable this setting (both enemies).

Click on Add Variable again to add another object variable. This variable will store the enemy’s health.

  • Variable Key
    Set to health.
  • Type
    Select Int.
  • Float Value
    enemy1: Set to 1 (Value).
    enemy2: Set to 2 (Value).

Copy the previous variable and change the following settings. This variable will store the points the player earns for killing this enemy.

  • Variable Key
    Set to points.
  • Float Value
    enemy1: Set to 100 (Value).
    enemy2: Set to 200 (Value).

Copy the previous variable and change the following settings. This variable will store the damage the enemy will deal to the player (will be handled in a later tutorial).

  • Variable Key
    Set to damage.
  • Float Value
    enemy1: Set to 10 (Value).
    enemy2: Set to 20 (Value).

Click on Add Variable again to add another object variable. This variable will store the enemy’s speed.

  • Variable Key
    Set to speed.
  • Type
    Select Float.
  • Float Value
    enemy1: Set to 6 (Value).
    enemy2: Set to 5 (Value).

That’s it for the object variables.

Enemy: Tick Machine

Next, we’ll add the Enemy schematic (handling the enemy’s movement) 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

  • Fixed Update
    Enable this setting.

Machine Execution Settings

  • Asset Type
    Select Schematic.
  • Schematic Asset
    Select Enemy.
  • Execution Type
    Select Single.
  • Update Type
    Select Fixed Update.

Flip: Tagged Machine

Now, we’ll add the Flip schematic using a tagged machine that will be stared by the tag flip. This will be called when the enemy changes direction.

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 flip.

Machine Execution Settings

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

EnemyHit: Tagged Machine

Next, we’ll add the EnemyHit schematic (handling the enemy being hit by a rocket) using a tagged machine that will be stared by the tag rocketHit.

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 rocketHit.

Machine Execution Settings

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

Resource Overrides (only enemy2)

Expand the Resource Overrides to change the used sprite. Since enemy1 only has 1 health (i.e. dies on the first hit) we only need a damage sprite for enemy2.

  • Override Sprites
    Enable this setting.

Click on Add Sprite to add a sprite that will be used.

  • Sprite
    Select char_enemy_alienShip-damaged.
    The sprites can be found at Assets/Tutorial Resources/Sprites/_Character/.

EnemyDeath: Tagged Machine

Finally, we’ll add the EnemyDeath schematic (handling the enemy’s death) using a tagged machine that will be stared by the tag die. This machine will later also be started through bombs.

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 die.

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 sprite.

  • Override Sprites
    Enable this setting.

Click on Add Sprite to add a sprite that will be used.

  • Sprite
    enemy1: Select char_enemy_alienSlug-dead.
    enemy2: Select char_enemy_alienShip-dead.
    The sprites can be found at Assets/Tutorial Resources/Sprites/_Character/.

And that’s it – we don’t need to apply the changes, since we’ve worked on the enemy prefabs directly.

Testing

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

The next tutorial will handle enemy spawners.