Setting up enemy game mechanics.
In this tutorial we’ll create schematics for the enemy’s movement, attack and death.
First, we’ll set up the enemy’s movement – the enemy will be moved using NavMesh.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Add Node > Value > Variable > Check Variables
This node is used to check for variable conditions. We’ll use it to check the health of the enemy and player using our template.
Click on Add Variable to add a variable condition.
Copy the variable condition and change the following settings.
Add Node > Movement > NavMesh > NavMesh Destination
This node is used to set the destination of a NavMesh agent. We’ll use it to move the enemy to the player’s position.
This node is connected to the Success slot of the Check Variables node.
Add Node > Game Object > Component > Enable Component
This node is used to enable/disable components. We’ll use it to disable the NavMesh agent component.
This node is connected to the Failed slot of the Check Variables node.
And that’s it for the schematic – click on Save Schematic and save it as EnemyMovement in Assets/Schematics/.
Next, we’ll create the schematic handling the enemy’s attack. The enemy will attack the player while being within the enemy’s trigger.
Create a new schematic and change the following settings.
We’ll set up local variables as Machine Start Variables 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.
Again, click on Add Start Variable to add another local start variable.
Add Node > Machine > Start Tagged Machine
This node is used to start a tagged machine. We’ll use it to start a tagged machine with the tag damage, which will handle reducing the target’s health. The actual damage is stored in the local float variable damage (local start variable of the machine).
Click on Add Tag to add a starting tag.
Add Node > Base > Wait
This node is used to wait for some time. We’ll use it to wait for the enemy’s attack timeout (local start variable).
And that’s it for the schematic – click on Save Schematic and save it as EnemyAttack in Assets/Schematics/.
When an enemy dies, we’ll play an audio clip, disable the collider, play a death animation and move the enemy’s game object down into the floor.
Since we’ll use this schematic for different enemies, we want to play different audio clips for them. Adding an audio clip as a resource will allow us to override it in the machine’s settings.
Click on Add Audio Clip Resource to add an audio clip resource.
We don’t select an actual audio clip – they’ll be defined in the machine component’s we’re using on the enemies.
Add Node > Audio > Audio > Play Sound
This node is used to play audio clips. We’ll use it to play the death audio clip resource.
Add Node > Game Object > Component > Emit Particles
This node is used to start/stop emitting particles. We’ll use it to start a death particle effect.
We’ll use this node to disable the capsule collider.
Add Node > Animation > Mecanim > Play Mecanim Animation
This node is used to play an animation or set parameters of an animator. We’ll use it to play the death animation of the enemy by setting the Dead trigger parameter.
Click on Add Parameter to add an parameter that will be changed.
Add Node > Value > Variable > Change Variables
This node is used to change variables. We’ll use it to increase the score by the enemy’s points. The score is stored in the global int variable score, the points are stored in the enemy’s object int variable points.
Click on Add Variable to add a variable change.
We’ll wait for a second to allow the enemy’s death animation to finish.
Add Node > Movement > Movement > Move Into Direction
This node is used to move a game object into a direction. We’ll use it to move the enemy into the floor.
And that’s it for this schematic – click on Save Schematic and save it as EnemyDeath in Assets/Schematics/.
Finally, we’ll set up the schematic that reduces the health and starts a tagged machine with the tag death in case the health is reduced to 0. This schematic will also be used by the player to take damage.
We’ll use it to play the hurt audio clip resource.
We’ll usethis node to reduce the health (object variable) by the damage, a local variable passed on by the schematic that started this schematic (tagged machine).
We’ll use this node to check if the health reached 0.
We’ll use this node to start the death tagged machine when the health is gone.
And that’s it for this schematic – click on Save Schematic and save it as TakeDamage in Assets/Schematics/.
The next tutorial will handle setting up the enemies.