Makinom - Game Toolkit for Unity
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • Extensions
    • API
  • Makinom 1
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get Makinom

Guide

Schematics

  • Setting the Player
  • Simple Character Controller
  • Mouse Orbit Camera
  • Random Waypoints

Breakout

  • Breakout Tutorial Introduction
  • 01 First Steps
  • 02 Player Controls
  • 03 Bricks
  • 04 Losing a Life
  • 05 UI Setup
  • 06 Sound Assignments

Space Shooter

  • Space Shooter Tutorial Introduction
  • 01 First Steps
  • 02 Player Move Controls
  • 03 Player Weapon Controls
  • 04 Hit and Destroy
  • 05 Asteroids
  • 06 Game Controller
  • 07 UI Setup
  • 08 Player’s Destruction
  • 09 Enemy Ship Mechanics
  • 10 Enemy Ship
  • 11 Moving the Background

Match 3

  • Match 3 Tutorial Introduction
  • 01 First Steps
  • 02 UI Setup
  • 03 Generating the Level
  • 04 Matching Jewels
  • 05 Destroying Jewels
  • 06 Game Controls
  • 07 Jewel Setup

Survival Shooter

  • Survival Shooter Tutorial Introduction
  • 01 First Steps
  • 02 Player Movement
  • 03 Player Shooting
  • 04 Enemy Mechanics
  • 05 Setting up the Enemies
  • 06 UI Setup
  • 07 Player’s Death
  • 08 Enemy Spawner

2D Roguelike

  • 2D Roguelike Tutorial Introduction
  • 01 First Steps
  • 02 Generating the Level
  • 03 Level Generation Machines
  • 04 Player Controls
  • 05 Walls, Food and Exit
  • 06 Game Manager and UI Setup
  • 07 Enemy Mechanics
  • 08 Game Over

2D Platformer

  • 2D Platformer Tutorial Introduction
  • 01 First Steps
  • 02 Player Movement
  • 03 Camera and Background
  • 04 Shooting Rockets
  • 05 Enemy Mechanics
  • 06 Setting up the Enemies
  • 07 Enemy Spawners
  • 08 Player Damage and Fall Remover
  • 09 Health Pickup
  • 10 Bomb Pickup
  • 11 Bomb Prefabs and Lay Bombs
  • 12 Pickup Spawner
  • 13 UI Setup
  • 14 Background Animations
  • Home
  • Guide
  • Tutorials
  • 2D Platformer
  • 06 Setting up the Enemies

06 Setting up the Enemies

Table of Contents
  • Object Variables
  • Enemy: Tick Machine
    • Start Settings
    • Machine Execution Settings
  • Flip: Tagged Machine
    • Start Settings
      • Machine Execution Settings
  • EnemyHit: Tagged Machine
    • Start Settings
    • Machine Execution Settings
    • Resource Overrides (only enemy2)
  • EnemyDeath: Tagged Machine
    • Start Settings
    • Machine Execution Settings
    • Resource Overrides
  • Testing

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 #

  • 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 #

  • 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 #

  • 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 #

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

Share This Article :
  • Facebook
  • Twitter
  • LinkedIn
  • Pinterest
Updated on January 7, 2021
Table of Contents
  • Object Variables
  • Enemy: Tick Machine
    • Start Settings
    • Machine Execution Settings
  • Flip: Tagged Machine
    • Start Settings
      • Machine Execution Settings
  • EnemyHit: Tagged Machine
    • Start Settings
    • Machine Execution Settings
    • Resource Overrides (only enemy2)
  • EnemyDeath: Tagged Machine
    • Start Settings
    • Machine Execution Settings
    • Resource Overrides
  • Testing
Sitemap
  • Features
  • Showcase
  • Guide
    • Documentation
    • Tutorials
    • Extensions
    • API
  • Makinom 1 Hub
    • Tutorials
    • Plugins
    • API
  • Support
  • Forum
  • Get Makinom
  • Contact
  • Blog
  • ORK Framework
  • gamingislove.com
Categories
  • Makinom 1 (97)
    • Tutorial (97)
      • 2D Platformer (14)
      • 2D Roguelike (8)
      • Breakout (6)
      • How-to (34)
      • Match 3 (6)
      • Schematic (4)
      • Scripting (6)
      • Space Shooter (11)
      • Survival Shooter (8)
  • News (11)
  • Release (68)
Search

© 2015 Gaming is Love e.U.

Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!