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.
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.
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.
Click on Add Start Variable to add a local start variable that will be exposed to the machine component’s inspector.
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).
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.
Click on Add Field to add a field/property that will be changed on the defined component/class.
That’s it for the schematic – click on Save Schematic and save it as RandomRotator in Assets/Schematics/.
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/.
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.
Click on Add Variable to add an object variable.
Copy the variable and change the following settings.
That’s it for the object variables.
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.
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.
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.
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.
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.
Click on Add Starting Tag to add a tag that can start this machine.
We don’t need to use resource overrides, since we used the asteroid’s particle effect and audio clip in the schematic.
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).
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.
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, which will spawn the enemy waves (only asteroids for now).
© 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!