Setting up the enemy ship’s game mechanics.
It’s time to create the schematics that handle the enemy ship’s game mechanics. We’ll create 2 new schematics, one for moving the ship and one for randomly flying evasive maneuvers along the X-axis (i.e. left and right).
First we’ll create the schematic for flying evasive maneuvers. The schematic will set the float object variable targetManeuver that will be used by another schematic (moving the enemy ship) as X-axis velocity. The maneuver will be played by a repeating auto machine component.
The maneuvers and actual moving is handled in 2 different schematics, because the maneuver will use wait times between starting and stopping a maneuver, while the mover needs to be started every fixed framerate frame (moving the rigidbody).
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 > Base > Wait
We’ll randomly wait for 0.5 to 1 seconds before starting a maneuver.
Add Node > Value > Float > Float Random
This node will store a random number between 2 defind numbers into a float variable. We’ll use it to set the maneuver’s target velocity into an object variable. The random number will be created using the local start variable dodge.
We’re using an object variable to make it available to the mover schematic for moving the ship.
We’ll randomly wait for 1 to 2 seconds before ending a maneuver.
Add Node > Value > Variable > Change Variables
The maneuver ended, so we’ll reset targetManeuver to 0.
Click on Add Variable to add a variable change.
We’ll randomly wait for 0 to 1 seconds before ending the schematic, which will restart the machine.
And that’s it for the schematic – click on Save Schematic and save it as EnemyManeuver in Assets/Schematics/.
Next we’ll create the schematic moving the enemy ship. The schematic is similar to the player mover and will use object float variable targetManeuver that was set by the maneuver schematic.
Create a new schematic by clicking on 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.
Copy the previous start variable and change the following settings.
Again, copy the previous start variable and change the following settings.
Add Node > Game Object > Rigidbody > Rigidbody Store Velocity
This node will store the current velocity of a game object into a Vector3 variable. We’ll use it to store the enemy ship’s velocity, because we’ll use the velocity along the X-axis to fade toward the evasive maneuver later.
Add Node > Value > Float > Float Move Towards
This node will fade a float value between two values over time and stores it into a float variable. We’ll use it to fade the current X-axis velocity toward the evasive maneuver target.
We’ll now set the velocity variable to the target maneuver and the speed (local start variable of the machine) of the enemy ship.
Add Node > Game Object > Rigidbody > Rigidbody Change Velocity
We’ll set the enemy ship’s velocity to the Vector3 value we’ve just stored into the local Vector3 variable velocity.
Add Node > Movement > Movement > Clamp Transform
This node will make sure the enemy ship’s position stays within a defined area. We’ll use local start variables of the machine component for that.
We’ll multiply the X-axis of the velocity by the local start variable variable tilt to slightly rotate the enemy ship when it’s flying left or right.
Add Node > Game Object > Rigidbody > Rigidbody Move Rotation
We’ll only rotate it on the Z-axis, using the X-axis of the velocity variable.
And that’s it for the schematic – click on Save Schematic and save it as EnemyMover in Assets/Schematics/.
The next tutorial will handle setting up the enemy ship.
© 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!