Game Toolkit for Unity
Setting up the player’s weapon controls.
In this tutorial we’ll create a schematic to let rockets hit other game objects (we’ll use that later when setting up our enemies and bomb crates) and add the fire controls to the PlayerControl schematic.
First, we’ll set up the schematic that lets the rocket hit other game objects.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
We need to add the rocket’s explosion prefab.
Click on Add Prefab Resource to add a prefab resource.
Add Name > Game Object > Game Object > Check Object Name
We’ll use this node to check if the object that was hit was another rocket – in that case, we don’t want to explode.
The rocket prefab uses the tag Bullet, so we’ll check for that.
Add Name > Game > Player > Is Player
We’ll use this node to check if we hit the player – we also don’t want to explode in that case.
This node is connected to the Failed slot of the Check Object Name node.
Add Name > Machine > Start Tagged Machine
We’ll use this node to start a tagged machine on the game object we hit. The rocketHit tag will either damage an enemy or explode a bomb crate that was hit – other game objects wont do anything.
This node is connected to the Failed slot of the Is Player node.
Click on Add Tag to add a starting tag.
Add Name > Audio > Audio > Play Sound At Point
We’ll use this node to play an explosion sound at the current position of the rocket (i.e. where we hit something).
Add Name > Game Object > Prefab > Spawn Prefab
We’ll use this node to spawn the explosion effect prefab.
Add Name > Movement > Rotation > Change Rotation
We’ll use this node to set the spawned prefab’s Z-axis rotation to a random value between 0 and 360.
Add Name > Game Object > Prefab > Destroy Prefab
We’ll use this node to destroy the prefab after some time.
Add Name > Game Object > Game Object > Destroy Object
Finally, we’ll destroy the rocket at the end.
That’s it for this schematic – click on Save Schematic and save it as Rocket in Assets/Schematics/.
Now, we’ll add the schematic to the rocket prefab using a trigger machine. You can find the prefab in Assets/Tutorial Resources/Prefabs/.
Add a trigger machine component (e.g. using the component menu: Makinom > Machines > Trigger Machine) and change the following settings.
That’s it for the rocket prefab – since we’re working on the prefab, we don’t need to apply the changes.
Next, we’ll add the weapon fire controls to the PlayerControl schematic – you probably have saved it in Assets/Schematics/ if you’ve followed the tutorial.
You can open the schematic directly by double clicking on it or by clicking on the Edit Schematic button in the inspector (when the schematic is selected).
First, we’ll add the rocket prefab to the schematic.
Now, we’ll change to layer 2 (Shoot) that we added as a last step when creating the schematic.
The following nodes are placed in layer 2: Shoot. In this layer, we’ll handle the player’s weapon fire.
Add Name > Input > Input Key
We’ll use this node to check if the player pressed the Fire input key.
This node is connected to the Next slot of the Gate Exit from layer 1.
Add Name > Input > Reset Input Axes
Since we’re running this in a Fixed Update tick machine, it’s possible that it’ll run more than once per frame. To prevent firing multiple rockets, we’ll reset the Fire input key.
This node is connected to the Fire slot of the Input Key node.
Add Name > Animation > Mecanim > Play Mecanim Animation
We’ll use this node to play the shooting animation of the player by setting the Shoot trigger parameter.
Click on Add Parameter to add an parameter that will be changed.
Add Name > Audio > Audio > Play Sound
We’ll use this node to play a firing sound on the player.
We’ll use this node to spawn the rocket prefab at the player’s gun.
Add Name > Value > Variable > Check Variables
We’ll use this node to check if the player is facing right – we’ll need to decide in which direction to move the rocket.
Click on Add Variable to add a variable condition.
We’ll use this node to set the rotation of the rocket.
This node is connected to the Success slot of the Check Variables node (i.e. we’re facing right).
Add Name > Game Object > Rigidbody > Rigidbody Change Velocity
We’ll use this node to set the velocity of the rocket.
Copy the previous Change Rotation node and connect it to the Failed slot of the Check Variables node (i.e. we’re facing left).
Change the following settings.
Copy the previous Rigidbody Change Velocity node and connect it to the 2nd Change Rotation node.
Finally, we’ll add a Layer Gate node to the reach the next layer. This node is connected to the Failed slot of the Input Key node and both Next slots of the Rigidbody Change Velocity nodes.
Right click on one of the slots and select Add Name > Gate to Layer > Add New Layer. This will create a new layer and add a layer gate to it.
To display the new layer, either double click on the on the node’s title or select it in the layer popup field in the upper right corner of the editor.
You can rename the layer by clicking on the Rename Layer icon right of the popup field – e.g. name the layer Bomb. Clicking on the icon again will stop editing the layer’s name.
This layer will handle laying bombs, we’ll continue here at a later time. For now, this schematic is finished – click on Save Schematic to save the changes.
Click on Play to test the game. You’ll now be able to fire rockets when pressing the Fire key – they’ll explode when hitting something.
The next tutorial will handle the enemy mechanics.
© 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!