Setting up the player’s movement controls.
In this tutorial we’ll do the basic player setup and create a schematic to control the movement.
The player’s basic setup involves adding object variables to store the player’s attributes and adding a simple schematic to set the player. Place the Player prefab (found at Assets/Tutorial Resources/Prefabs/) in the scene and position it at X=0, Y=0, Z=0.
First, we’ll add object variables to the player’s game object. Add an Object Variables component (e.g. using the component menu: Makinom > Scenes > Object Variables).
Change the following settings of the object variables component.
Click on Add Variable to add a new variable to the object variables. This variable will be used to store the player’s health. When the health reaches 0, the player’s ship will be destroyed.
Again, click on Add Variable. This variable will be used to store the player’s fire rate (i.e. time between shots).
Now, we’ll use a schematic to set the player when the level starts and add it with an Auto Machine component.
Follow the steps in this schematic tutorial – it explains how to create the schematic and add an auto machine to the game object.
Next, we’ll create a schematic to handle the player’s movement control. Open the Makinom editor, navigate to Schematics and create a new schematic.
The player’s game object will be moved by changing the Rigidbody component’s velocity. Additionally, we’ll tilt the game object according to the horizontal movement.
Please note that the machine component used to play the schematic will set up some of the used local variables.
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.
These variables will be used for the player’s movement (speed, tilt) and limiting the area the player can move in.
Copy the previous start variable and change the following settings.
Again, copy the previous start variable and change the following settings.
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 the player’s input as a Vector3 value, 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 player’s game object.
The Variable Settings define where the Vector3 value will be stored.
Now, we’ll define the Vector3 value using the player’s input.
Finally, we’ll multiply the defined Vector3 value by a float value, using a local variable.
Add Node > Game Object > Rigidbody > Rigidbody Change Velocity
This node will set the velocity of a rigidbody component. We’ll set the player’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 player’s position stays within a defined area. We’ll use local float variables defined as start variables in the machine component for that.
Add Node > Value > Variable > Change Variables
This node will change variables. We’ll multiply the X-axis of the velocity by the local float variable tilt (start variable).
Click on Add Variable to add a variable change.
Add Node > Game Object > Rigidbody > Rigidbody Move Rotation
This node will rotate the rigidbody. 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 PlayerMover in Assets/Schematics/.
The player is moved using a Rigidbody component, i.e. we’ll need to Fixed Update for the physics updates.
Add a Tick Machine component to the player’s game object (e.g. using the component menu: Makinom > Machines > Tick Machine). Change the following settings.
The Machine Start Variables we’ve set up in the schematic are automatically added here with their default values – since the default values are already what we need, we don’t have more to do here. Make sure all variables are enabled.
And that’s it for now – apply the changes to the prefab by clicking on Overrides > Apply All (top of the inspector).
Click on Play to test the game. You’ll be able to move the player around in a limited area of the screen.
The next tutorial will handle the player weapon controls.
© 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!