---
title: 09 Enemy Ship Mechanics
description: "Setting up the enemy ship's game mechanics. It's time to create the schematics that handle the enemy ship's game mechanics. We'll create 2 new schematics, one for moving the ship and one for randomly flying evasive maneuvers along the X-axis…"
url: "https://makinom.com/guide/tutorials/space-shooter/09-enemy-ship-mechanics/"
updated: "2020-12-17"
category: Space Shooter
---

# 09 Enemy Ship Mechanics

Setting up the enemy ship's game mechanics.

It's time to create the schematics that handle the enemy ship's game mechanics. We'll create 2 new schematics, one for moving the ship and one for randomly flying evasive maneuvers along the X-axis (i.e. left and right).

# Enemy Maneuver: Schematic

First we'll create the schematic for flying evasive maneuvers. The schematic will set the float object variable *targetManeuver* that will be used by another schematic (moving the enemy ship) as X-axis velocity. The maneuver will be played by a repeating auto machine component.

The maneuvers and actual moving is handled in 2 different schematics, because the maneuver will use wait times between starting and stopping a maneuver, while the mover needs to be started every fixed framerate frame (moving the rigidbody).

Open the Makinom editor, navigate to **Schematics** and create a new schematic. Change the following settings.

[![](https://makinom.com/wp-content/uploads/makinom2_game_tutorial_space_shooter_schematic_enemy_maneuver.png)](https://makinom.com/wp-content/uploads/makinom2_game_tutorial_space_shooter_schematic_enemy_maneuver.png)

## Settings

We'll set up a local variable as *Machine Start Variable* for easy setup in the machine component at a later time. When using the schematic in a machine component, the defined start variables will be added automatically, using their default values.

### Machine Start Variables

Click on *Add Start Variable* to add a local start variable that will be exposed to the machine component's inspector.

- **Variable Key**
   Set to *dodge*.
- **Type**
   Select *Float*.
- **Default Value**
   Set to *5*.

## Wait

*Add Node > Base > Wait*

We'll randomly wait for 0.5 to 1 seconds before starting a maneuver.

- **Random**
   *Enable* this setting.
- **Time (s)**
   Set to *0.5* (Value).
- **Time 2 (s)**
   Set to *1* (Value).

## Float Random

*Add Node > Value > Float > Float Random*

This node will store a random number between 2 defind numbers into a float variable. We'll use it to set the maneuver's target velocity into an object variable. The random number will be created using the local start variable *dodge*.

We're using an object variable to make it available to the mover schematic for moving the ship.

### Variable Settings

- **Variable Key**
   Set to *targetManeuver*.
- **Variable Origin**
   Select *Object*.
- **Object**
   Select *Machine Object*.
- **Operator**
   Select *Set*.

### Minimum Value

- **Minimum Value**
   Select *Variable >**Float Variable*.
- **Variable Key**
   Set to *dodge*.
- **Variable Origin**
   Select *Local*.
- **Math Function**
   Select *Negate*.
   This will use -dodge.

### Maximum Value

- **Maximum Value**
   Select *Variable >**Float Variable*.
- **Variable Key**
   Set to *dodge*.
- **Variable Origin**
   Select *Local*.

## Wait

*Add Node > Base > Wait*

We'll randomly wait for 1 to 2 seconds before ending a maneuver.

- **Random**
   *Enable* this setting.
- **Time (s)**
   Set to *1* (Value).
- **Time 2 (s)**
   Set to *2* (Value).

## Change Variables

*Add Node > Value > Variable > Change Variables*

The maneuver ended, so we'll reset *targetManeuver* to 0.

Click on *Add Variable* to add a variable change.

- **Change Type**
   Select *Variable*.
- **Variable Key**
   Select *targetManeuver*.
- **Variable Origin**
   Select *Object*.
- **Object**
   Select *Machine Object*.
- **Type**
   Select *Float*.
- **Operator**
   Select *Set*.
- **Float Value**
   Set to *0* (Value)*.*

## Wait

*Add Node > Base > Wait*

We'll randomly wait for 0 to 1 seconds before ending the schematic, which will restart the machine.

- **Random**
   *Enable* this setting.
- **Time (s)**
   Set to *0.5* (Value).
- **Time 2 (s)**
   Set to *1* (Value).

And that's it for the schematic - click on *Save Schematic* and save it as *EnemyManeuver* in *Assets/Schematics/*.

# Enemy Mover: Schematic

Next we'll create the schematic moving the enemy ship. The schematic is similar to the player mover and will use object float variable *targetManeuver* that was set by the maneuver schematic.

Create a new schematic by clicking on *New Schematic* and change the following settings.

[![](https://makinom.com/wp-content/uploads/makinom2_game_tutorial_space_shooter_schematic_enemy_mover.png)](https://makinom.com/wp-content/uploads/makinom2_game_tutorial_space_shooter_schematic_enemy_mover.png)

## Settings

We'll set up local variables as *Machine Start Variables* for easy setup in the machine component at a later time. When using the schematic in a machine component, the defined start variables will be added automatically, using their default values.

### Machine Start Variables

Click on *Add Start Variable* to add a local start variable that will be exposed to the machine component's inspector.

- **Variable Key**
   Set to *speed*.
- **Type**
   Select *Float*.
- **Default Value**
   Set to *-5*.

Copy the previous start variable and change the following settings.

- **Variable Key**
   Set to *tilt*.
- **Default Value**
   Set to -*5*.

Again, copy the previous start variable and change the following settings.

- **Variable Key**
   Set to *xMin*.
- **Default Value**
   Set to *-6*.

Again, copy the previous start variable and change the following settings.

- **Variable Key**
   Set to *xMax*.
- **Default Value**
   Set to *6*.

Again, copy the previous start variable and change the following settings.

- **Variable Key**
   Set to *zMin*.
- **Default Value**
   Set to *-20*.

Again, copy the previous start variable and change the following settings.

- **Variable Key**
   Set to *zMax*.
- **Default Value**
   Set to *20*.

## Rigidbody Store Velocity

*Add Node > Game Object > Rigidbody > Rigidbody Store Velocity*

This node will store the current velocity of a game object into a Vector3 variable. We'll use it to store the enemy ship's velocity, because we'll use the velocity along the X-axis to fade toward the evasive maneuver later.

### Variable Settings

- **Variable Key**
   Set to *velocity*.
- **Variable Origin**
   Select *Local*.
- **Operator**
   Select *Set*.

### Rigidbody Object

- **Object**
   Select *Machine Object*.

## Float Move Towards

*Add Node > Value > Float > Float Move Towards*

This node will fade a float value between two values over time and stores it into a float variable. We'll use it to fade the current X-axis velocity toward the evasive maneuver target.

### Variable Settings

- **Variable Key**
   Set to *newManeuver*.
- **Variable Origin**
   Select *Local*.
- **Operator**
   Select *Set*.

### Current Value

- **Current Value**
   Select *Variable >**Vector3 Variable* and *X*.
- **Variable Key**
   Set to*velocity*.
- **Variable Origin**
   Select *Local*.

### Target Value

- **Target Value**
   Select *Variable >**Float Variable*.
- **Variable Key**
   Set to *targetManeuver*.
- **Variable Origin**
   Select *Object*.
- **Object**
   Select*Machine Object*.

### Maximum Delta

- **Maximum Delta**
   Set to *0.5* (Value).
   The maximum velocity change per frame is 0.5.

## Change Variables

*Add Node > Value > Variable > Change Variables*

We'll now set the *velocity* variable to the target maneuver and the speed (local start variable of the machine) of the enemy ship.

Click on *Add Variable* to add a variable change.

- **Change Type**
   Select *Variable*.
- **Variable Key**
   Select *velocity*.
- **Variable Origin**
   Select *Local*.
- **Type**
   Select *Vector3*.
- **Operator**
   Select *Set*.
- **Vector3 Value**
   Select *Value >**Set Axis*.
- **X-Axis**
   Select *Variable >**Float Variable*
- **Variable Key (X-Axis)**
   Set to *newManeuver*.
- **Variable Origin (X-Axis)**
   Select *Local*.
- **Y-Axis**
   Set to *0* (Value).
- **Z-Axis**
   Select *Variable >**Float Variable*.
- **Variable Key (Z-Axis)**
   Set to *speed*.
- **Variable Origin (Z-Axis)**
   Select *Local*.

## Rigidbody Change Velocity

*Add Node > Game Object > Rigidbody > Rigidbody Change Velocity*

We'll set the enemy ship's velocity to the Vector3 value we've just stored into the local Vector3 variable *velocity*.

### Rigidbody Object

- **Object**
   Select *Machine Object*.

### Velocity

- **Vector3 Type**
   Select*Vector3 Variable*.
- **Variable Key**
   Set to *velocity*.
- **Variable Origin**
   Select *Local*.

## Clamp Transform

*Add Node > Movement > Movement > Clamp Transform*

This node will make sure the enemy ship's position stays within a defined area. We'll use local start variables of the machine component for that.

### Clamp Object

- **Object**
   Select *Machine Object*.
- **Value Origin**
   Select *Position*.

### Clamp X-Axis

- **Clamp X-Axis**
   *Enable* this setting.
- **X-Axis Minimum**
   Select *Variable >**Float Variable*.
- **Variable Key (X-Axis Minimum)**
   Set to *xMin*.
- **Variable Origin (X-Axis Minimum)**
   Select*Local*.
- **X-Axis Maximum**
   Select *Variable >**Float Variable*.
- **Variable Key (X-Axis Maximum)**
   Set to *xMax*.
- **Variable Origin (X-Axis Maximum)**
   Select *Local*.

### Clamp Z-Axis

- **Clamp Z-Axis**
   *Enable* this setting.
- **Z-Axis Minimum**
   Select *Variable >**Float Variable*.
- **Variable Key (Z-Axis Minimum)**
   Set to *zMin*.
- **Variable Origin (Z-Axis Minimum)**
   Select*Local*.
- **Z-Axis Maximum**
   Select *Variable >**Float Variable*.
- **Variable Key (Z-Axis Maximum)**
   Set to *zMax*.
- **Variable Origin (Z-Axis Maximum)**
   Select *Local*.

## Change Variables

*Add Node > Value > Variable > Change Variables*

We'll multiply the X-axis of the velocity by the local start variable variable *tilt* to slightly rotate the enemy ship when it's flying left or right.

Click on *Add Variable* to add a variable change.

- **Change Type**
   Select *Variable*.
- **Variable Key**
   Select *velocity*.
- **Variable Origin**
   Select *Local*.
- **Type**
   Select *Axis Vector3*.
- **Axis**
   Select *X*.
- **Operator**
   Select *Multiply*.
- **Float Value**
   Select *Variable >**Float Variable*.
- **Variable Key**
   Set to *tilt*.
- **Variable Origin**
   Select *Local*.

## Rigidbody Move Rotation

*Add Node > Game Object > Rigidbody > Rigidbody Move Rotation*

We'll only rotate it on the Z-axis, using the X-axis of the *velocity* variable.

### Rigidbody Object

- **Object**
   Select *Machine Object*.

### Rotation

- **Vector3 Type**
   Select *Value >**Set Axis*.
- **X-Axis**
   Set to *0* (Value).
- **Y-Axis**
   Set to *0* (Value).
- **Z-Axis**
   Select *Variable >**Vector3 Variable* and *X*.
- **Variable Key**
   Set to *velocity*.
- **Variable Origin**
   Select *Local*.

And that's it for the schematic - click on *Save Schematic* and save it as *EnemyMover* in *Assets/Schematics/.*

The next tutorial will handle [setting up the enemy ship](https://makinom.com/guide/tutorials/space-shooter/10-enemy-ship/).
