Setting up the player’s weapon controls.
In this tutorial we’ll create a schematic to control the player’s weapon and moving the fired bolt. The schematic will be simple and can be reused later to fire the enemy shots as well.
First, we’ll create the schematic to fire the weapon. The schematic will simply spawn a prefab and wait for the fire rate to pass. The player input firing the weapon is handled by an Interaction Machine component we’ll use to play the schematic.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
The start node is used for basic setup of a schematic and to add actors and resources. We’ll add a prefab resource to make use of the game object pools we’ve set up, and an audio clip resource. Using resoruces also allows us to override the prefabs and audio clips and reuse the schematic for the enemy ship.
Click on Add Prefab Resource to add a prefab resource. Make sure that Destroy Prefabs is disabled.
Click on Add Audio Clip Resource to add an audio clip resource.
Add Node > Game Object > Prefab > Spawn Prefab
This node will spawn the prefab. We’ll spawn it at a child object of the player.
Add Node > Base > Wait
This node waits for a defined amount of seconds. We’ll use it to wait for the fire rate (object variable).
And that’s it for the schematic – click on Save Schematic and save it as FireShot in Assets/Schematics/.
Now, we’ll add an interaction machine component to the player’s game object. Select the game object in the scene and add the component (e.g. using the component menu: Makinom > Machines > Interaction Machine). Change the following settings.
And that’s it for the player for now. Click on Overrides > Apply All (top of the inspector) to apply the changes to the prefab.
Next, we’ll create a schematic to move a game object forward. This will be used to move the bolts, asteroids and enemy ships.
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
This node will multiply a Vector3 value with a float value and store it into a Vector3 variable.
We’ll use a game object’s forward direction, multiply it by the movement speed (will be defined as start variable in the machine component) and store it into a local Vector3 variable. This will be the velocity used to move the game object.
Add Node > Game Object > Rigidbody > Rigidbody Change Velocity
This node will set the velocity of a rigidbody component. We’ll set the game object’s velocity to the Vector3 value we’ve just stored into the local Vector3 variable velocity.
And that’s it for the schematic – click on Save Schematic and save it as Mover in Assets/Schematics/.
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.
We’ll add it to the Bolt prefab (found at Assets/Tutorial Resources/Prefabs/), add an auto machine component (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.
And that’s it for the Bolt prefab for now. Since we added the component directly to the prefab, we don’t need to apply the changes.
Currently, the fired bolts would continue flying, leading to more and more prefabs being instantiated and increasing the game object pool.
To prevent this, we’ll create a simple prefab that will disable all objects that exit a trigger – the boundary of the level. Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Add Node > Game Object > Game Object > Activate Object
This node will enable and disable game objects. We’ll use it to disable the game object that started the machine (i.e. whatever left the trigger).
And that’s it for the schematic – click on Save Schematic and save it as BoundaryExit in Assets/Schematics/.
Select the Boundary game object in the scene’s hierarchy. The game object has a collider (used as trigger) set up around the level.
We’ll use a Trigger Machine component to check for game objects that left the trigger. Add the component to the game object (e.g. using the component menu: Makinom > Machines > Trigger Machine). Change the following settings.
And that’s it for now – don’t forget to save the scene.
Click on Play to test the game. You’ll now be able to fire bolts, which will move upwards. Once the bolts leave the boundary, they’ll be disabled and can be reused in the game object pool.
The next tutorial will handle hit and destroy.
© 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!