10 Enemy Ship

Setting up the enemy ship’s machines.

After creating the schematics for moving the enemy ship, it’s time to set up the machine components on the prefab. However, first we’ll add the machine components to the enemy’s weapon bolt.

Setting up the Enemy Bolt #

Select the Bolt Enemy prefab (found at Assets/Tutorial Resources/Prefabs/). We’ll add a Mover schematic and a Hit schematic like we did with the player’s bolt.

Mover: Auto Machine #

The Mover schematic will be added using an auto machine component. The schematic will set the game object’s velocity when it’s added to the scene.

Add an auto machine component to the Bolt Enemy prefab (e.g. using the component menu: Makinom > Machines > Auto Machine). Change the following settings.

Start Settings #

  • Enable
    Enable this setting.

Machine Execution Settings #

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

Local Start Variables #

The Machine Start Variable we’ve set up in the schematic is automatically added here, so all we need to do is adjust it to our needs. Make sure the variable is enabled.

  • speed
    Set to 20.

Hit: Trigger Machine #

We’ll add the Hit schematic using a trigger machine component. Add a trigger machine component (e.g. using the component menu: Makinom > Machines > Trigger Machine).

Change the following settings.

Start Settings #

  • Trigger Enter
    Enable this setting.

Machine Execution Settings #

  • Schematics Asset
    Select Hit.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Local Start Variables #

The Machine Start Variable we’ve set up in the schematic is automatically added here, the default value is all we need. Make sure the variable is enabled.

That’s it for the Enemy Bolt prefab. Since we added the component directly on the prefab, we don’t need to apply the changes.

Setting up the Enemy Ship #

Select the Enemy Ship prefab (found at Assets/Tutorial Resources/Prefabs/), we’ll add multiple components to it.

Object Variables #

First, we’ll set up the object variables of the enemy ship. 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 enemy ships can be spawned multiple times, so we don’t want them to share their variables.
  • Always Initialize
    Enable this setting.
    This makes sure that the variables will be initialized each time the game object is spawned/activated.

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
    Set to 1 (Value).

Copy the variable and change the following settings.

  • Variable Key
    Set to points.
  • Float Value
    Set to 100 (Value).

Click on Add Variable to add an object variable.

  • Variable Key
    Set to fireRate.
    Select the Value string type.
  • Type
    Select Float.
  • Operator
    Select Set.
  • Float Value
    Set to 1.5 (Value).

That’s it for the object variables.

Enemy Mover: Tick Machine #

The enemy ship is moved using a rigidbody component, i.e. we’ll need to Fixed Update for the physics updates.

Add a tick machine component to the prefab (e.g. using the component menu: Makinom > Machines > Tick Machine). Change the following settings.

Start Settings #

  • Fixed Update
    Enable this setting.
    The machine will be started in the fixed framerate frame.

Machine Execution Settings #

  • Schematic Asset
    Select EnemyMover.
  • Execution Type
    Select Single.
    The machine can only be executed once at a time.
  • Update Type
    Select Fixed Update.

Local Start Variables #

The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values – since the default values are already what we need, we don’t have more to do here. Make sure all variables are enabled.

Enemy Maneuver: Auto Machine #

We’ll add the enemy maneuver schematic using a repeating auto machine component. This will restart the machine after it finished executing.

Add an auto machine component to the prefab (e.g. using the component menu: Makinom > Machines > Auto Machine) and change the following settings.

Start Settings #

  • Enable
    Enable this setting.
  • Repeat Execution
    Enable this setting.
    The machine will retry executing after it ended.

Machine Execution Settings #

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

Local Start Variables #

The Machine Start Variable we’ve set up in the schematic is automatically added here, the default value is all we need. Make sure the variable is enabled.

Destroy: Tagged Machine #

The Destroy schematic handles the destruction of a game object, spawning a particle effect prefab and playing and audio clip. The tagged machine component we’ll use for that will be started by the Hit schematic using the tag destroy.

Add a tagged machine component to the prefab (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 destroy.

Machine Execution Settings #

  • Schematics Asset
    Select Destroy.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.
  • Stop On Destroy
    Disable this setting.
    This will allow the machine to continue when the game object was destroyed or disabled.

Resource Overrides #

First, we’ll override Prefab 0 used by the schematic.

  • Override Prefabs
    Enable this setting.

Click on Add Prefab to add a prefab that will be used.

  • Prefab
    Select explosion_enemy.

Now, we’ll override Audio Clip 0 used by the schematic.

  • Override Audio Clips
    Enable this setting.

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

  • Audio Clip
    Select explosion_enemy.

Hit: Trigger Machine #

The Hit schematic reduces the health of game objects that are hit by the enemy ship. If the health drops to 0, it will start the destroy tagged machine.

The hit mechanic will use a trigger, add a trigger component to the asteroid prefabs (e.g. using the component menu: Makinom > Machines > Trigger Machine).

Start Settings #

  • Trigger Enter
    Enable this setting.

Machine Execution Settings #

  • Schematics Asset
    Select Hit.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.

Local Start Variables #

The Machine Start Variable we’ve set up in the schematic is automatically added here, the default value is all we need. Make sure the variable is enabled.

Fire Shot: Auto Machine #

Finally, we’ll add the FireShot schematic using a repeating auto machine. This will fire the enemy’s bolts according to the enemy’s fire rate.

Add an auto machine component to the prefab (e.g. using the component menu: Makinom > Machines > Auto Machine) and change the following settings.

Start Settings #

  • Enable
    Enable this setting.
  • Start Delay (s)
    Set to 0.5.
    The enemy ship will start firing after 0.5 seconds.
  • Repeat Execution
    Enable this setting.
    The machine will retry executing after it ended.

Machine Execution Settings #

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

Resource Overrides #

Expand the Resource Overrides to change the used prefab and audio clip.

First, we’ll override Prefab 0 used by the schematic.

  • Override Prefabs
    Enable this setting.

Click on Add Prefab to add a prefab that will be used.

  • Prefab
    Select Bolt Enemy.

Now, we’ll override Audio Clip 0 used by the schematic.

  • Override Audio Clips
    Enable this setting.

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

  • Audio Clip
    Select weapon_enemy.

That’s it for the Enemy Ship prefab. Since we added the component directly on the prefab, we don’t need to apply the changes.

Adjusting the Game Controller #

To get the enemy ship into the game, we’ll need to add it to the GameController schematic. Open the schematic, either through the Makinom editor, by double clicking on the asset file in the project view (can be found at Assets/Schematics/) or through the Edit Schematic button in the asset file’s inspector.

Settings #

Select the Settings node of the schematic and change the following settings.

Prefabs #

Click on Add Prefab in the Hazards prefab (Prefab 0).

  • Prefab
    Select Enemy Ship.
    Can be found at Assets/Tutorial Resources/Prefabs/.
  • Use Pooling
    Enable this setting.

And that’s it – click on Save Schematic to save the changes.

Testing #

Click on Play to test the game. The enemy waves will now also contain enemy ships. The enemy will fly evasive maneuvers randomly and fire bolts at the player.

The final tutorial will be short and simple – moving the background.