Setting up the player’s damage, death and the fall remover.
In this tutorial we’ll create 2 schematics – one handling the player taking damage from enemies and death, the other removing everything that falls into the river (with a splash) and restarting the game if the player died.
First, we’ll create the schematic that handles the player taking damage from touching enemies and dying when the health is gone. The schematic will be added to the player using a collision machine.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
We’ll add an audio clip resource that will be played when the player takes damage.
Click on Add Audio Clip Resource to add an audio clip resource.
We’ll use 4 audio clips, click on Add Audio Clip to add more clips.
Add Node > Value > Variable > Change Variables
We’ll use this node to change the player’s health using the enemy’s damage, and store the force that we’ll use to push the player away from the enemy.
Click on Add Variable to add a variable change.
Click on Add Variable again to add another variable change.
Copy the previous variable change.
Add Node > Game Object > Rigidbody > Rigidbody Add Force
We’ll use this node to push the player away from the enemy, using the force we just stored.
Add Node > Value > Variable > Check Variables
We’ll use this node to check if the player’s health reached 0.
Click on Add Variable to add a variable condition.
Add Node > Game Object > Collider > Collider Change Trigger
The following nodes handle the player’s death. We’ll use this node to set the colliders on the player to be triggers, letting him fall through the ground.
This node is connected to the Success slot of the Check Variables node.
Add Node > Game Object > Renderer > Change Sorting Layer
We’ll use this node to change the sorting layer of the player to have him nicely display above the rest of the level while falling down.
Add Node > Game > Game > Change Game State
We need to inactivate the In Control game state to stop the player controls.
Add Node > Animation > Mecanim > Play Mecanim Animation
Finally, we’ll play the player’s death animation by setting the Die trigger parameter.
Click on Add Parameter to add a parameter change.
That’s it for the schematic – click on Save Schematic and save it as PlayerDamage in Assets/Schematics/.
Now, we’ll add the schematic to the player using a collision machine. We’ll limit the machine to only start when colliding with game objects tagged Enemy.
Select the hero game object in the scene hierarchy, add a collission machine component (e.g. using the component menu: Makinom > Machines > Collision Machine) and change the following settings.
The Starting Objects settings handle which game objects can start the machine.
Click on Add Check to add a game object check for the objects we collide with.
That’s it for the player’s game object – apply the changes to the prefab by clicking on Overrides > Apply All (top of the inspector).
Next, we’ll set up the schematic that will remove everything that falls into the river. When something falls into the river, we’ll display a splash effect and – if the game object is the player – restart the game. The player falling into the river can happen in 2 ways – the player running into it, or the player dying and falling down – both result in game over.
We’ll display a splash game object (an animated sprite) at the position something fell into the river, i.e. we need a prefab resource.
Click on Add Prefab Resource to add a prefab resource
Add Node > Game Object > Prefab > Spawn Prefab
We’ll use this node to spawn the splash prefab at the position of the game object that fell into the river.
Add Node > Game Object > Prefab > Destroy Prefab
We’ll use this node to destroy the splash prefab after 0.5 seconds.
Add Node > Audio > Audio > Play Sound At Point
We’ll use this node to play a splash sound at the position something fell into the river.
Add Node > Game > Player > Is Player
We’ll use this node to check if the game object is the player.
Add Node > Game Object > Game Object > Destroy Object
In case the game object isn’t the player, we’ll destroy it immediately.
This node is connected to the Failed slot of the Is Player node.
In case the game object is the player, we’ll inactivate the In Control game state (stopping the controls).
This node is connected to the Success slot of the Is Player node.
Now we’ll destroy the player.
Add Node > Machine > Stop Global Machine
We’ll use this node to stop a running global machine that handles spawning pickups. We haven’t yet set it up, so just select the default global machine (which is set up automatically in a new project), we’ll set it up later for spawning the pickups.
Add Node > Base > Wait
We’ll wait for 2 seconds before reloading the scene.
Add Node > Game > Scene > Load Scene
We’ll use this node to reload the scene.
We’ll use this node to reset the score and bombs carried by the player.
Copy the previous variable.
Finally, we’ll activate the In Control game state to allow the player controls again (this is already after reloading the scene).
And that’s it for the schematic – click on Save Schematic and save it as FallRemover in Assets/Schematics/.
The FallRemover schematic will be added to the killTrigger game object in the scene. Select it in the scene hierarchy and add a trigger machine component (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 start the game. The player can now take damage and be killed. Falling into the river will reload the scene (i.e. game over).
The next tutorial will handle the health pickup.