---
title: 05 Asteroids
description: "Setting up the asteroids. The game will have 3 different asteroids. We'll need another schematic to randomly rotate the asteroids, the rest of the needed schematics is already set up. # Random Rotator: Schematic This schematic will randomly rotate the asteroid's…"
url: "https://makinom.com/guide/tutorials/space-shooter/05-asteroids/"
updated: "2020-12-17"
category: Space Shooter
---

# 05 Asteroids

Setting up the asteroids.

The game will have 3 different asteroids. We'll need another schematic to randomly rotate the asteroids, the rest of the needed schematics is already set up.

# Random Rotator: Schematic

This schematic will randomly rotate the asteroid's game object by setting the rigidbody's angular velocity. 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_random_rotator.png)](https://makinom.com/wp-content/uploads/makinom2_game_tutorial_space_shooter_schematic_random_rotator.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 *tumble*.
- **Type**
   Select *Float*.
- **Default Value**
   Set to *5*.

## Vector3 Multiply

*Add Node > Value > Vector > Vector3 Multiply*

We'll store the velocity into a local Vector3 variable, using a randomly generated Vector3 value and the local float variable *tumble* (local start variable of the machine component).

### Variable Settings

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

### Vector3 Value

- **Vector3 Type**
   Select *Random >**Random Inside Sphere*.
   This will create a random Vector3 value with X, Y and Z being randomly between 0 and 1.

### Multiply By

- **Multiply By**
   Select *Variable >**Float Variable*.
- **Variable Key**
   Select *tumble*.
- **Variable Origin**
   Select *Local*.

## Change Fields

*Add Node > Function > Change Fields*

This node will change fields and properties of a component (or class) using reflection. Since there is no specific node to change the angular velocity of a rigidbody, we'll use this node to set the value instead.

### Field Settings

- **Class Origin**
   Select *Component*.
- **Class Name**
   Set to *Rigidbody*.

Click on *Add Field* to add a field/property that will be changed on the defined component/class.

- **Field Name**
   Set to *angularVelocity*.
- **Is Property**
   *Enable* this setting.
   The rigidbody's angular velocity is a property, not a field.
- **Field Type**
   Select *Vector3*.
- **Vector3 Type**
   Select *Vector3 Variable*.
- **Variable Key**
   Set to *velocity*.
- **Variable Origin**
   Select *Local*.

### Object

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

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

# Setting up the Asteroids

The setup for all 3 asteroids is the same (except for minimal differences in the *Object Variables*). The following component setup can be repeated for all asteroid prefabs, or you can just copy the components and paste them on the other asteroids.

You can copy a component by right-clicking on the component's name and selecting *Copy Component* in the context menu. To paste the component on a game object, right-click on any component's name and select *Paste Component As New* in the context menu.

The asteroid prefabs (*Asteroid 1*, *Asteroid 2* and *Asteroid 3*) can be found at *Assets/Tutorial Resources/*.

## Object Variables

First, we'll set up the object variables of the asteroids. 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 asteroids 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**
   Asteroid 1: Set to *1* (Value).
   Asteroid 2: Set to *2* (Value).
   Asteroid 3: Set to *3* (Value).
   The asteroids will have different health values, i.e. asteroid 1 will need 1 hit to be destroyed, asteroid 3 will need 3 hits.

Copy the variable and change the following settings.

- **Variable Key**
   Set to *points*.
- **Float Value**
   Asteroid 1: Set to *50* (Value).
   Asteroid 2: Set to *75* (Value).
   Asteroid 3: Set to *100* (Value).
   The asteroids will add different points to the score.

That's it for the object variables.

## Mover: Auto Machine

Next, we'll add the *Mover* schematic using an auto machine component. The schematic will move a game object by setting the rigidbody's velocity.

Add the component to the asteroid prefabs (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 *-5*.

## Random Rotator: Auto Machine

Now, we'll add the *RandomRotator *schematic using an auto machine component. The schematic will randomly rotate a game object by setting the rigidbody's angular velocity.

Add the component to the asteroid prefabs (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 *RandomRotator*.
- **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, 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 the component to the asteroid 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 *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.

We don't need to use resource overrides, since we used the asteroid's particle effect and audio clip in the schematic.

## Hit: Trigger Machine

The *Hit* schematic reduces the health of game objects that are hit by the asteroids. 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.

Unlike the *Bolt* setup, we don't need to use *Start By Other* or *Limit Layers*, because the asteroids will only need to hit the player's game object.

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

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

The next tutorial will handle the [game controller](https://makinom.com/guide/tutorials/space-shooter/06-game-controller/), which will spawn the enemy waves (only asteroids for now).
