Game Toolkit for Unity
Setting up the player controls.
In this tutorial we’ll do the basic player setup and create 2 schematics for the player’s controls – one for moving the player left and right, one for shooting the ball at the start.
We’ll add a simple schematic to set the player – select the Paddle game object in the scene (it’s an already added instance of the Paddle prefab found at Assets/Tutorial Resources/Prefabs/).
We’ll use a schematic to set the player when the level starts or the player is spawned, and add it using 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 (the Paddle will be the player).
Next, we’ll create a schematic to handle the player’s movement control. The control will simply move the player left and right within defined bounds.
Open the Makinom editor, navigate to Schematics and create a new schematic. 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.
Copy the previous start variable.
Again, copy the previous start variable.
Next, we’ll add nodes – make sure to use the context menu’s search to quickly find the nodes.
Add Node > Movement > Movement > Move
We’ll use this node to move the paddle left and right based on the Horizontal input key. The movement speed of the paddle will be stored in a local start variable of the Tick Machine that will play the schematic.
The X-axis will be changed by using the Horizontal input key.
The Y and Z-axis will not be changed.
The movement will be based on the delta time, i.e. the time since the last frame.
Add Node > Movement > Movement > Clamp Transform
We’ll use this node to clamp the paddle’s position along the X-axis to stay within the level. The minimum and maximum values are stored in local start variables of the Tick Machine that plays the schematic.
The X-Axis Minimum is stored in a local start variable named xMin.
The X-Axis Maximum is stored in a local start variable named xMax.
We don’t need to clamp on the Y and Z axis.
That’s it for this schematic – click on Save Schematic and save it as Paddle in Assets/Schematics/.
Next, we’ll create the schematic to shoot the ball to start the game. The ball is mounted to the paddle first, in order to move it with the paddle before firing it. In this schematic, we’ll unmount the ball from the paddle, set a bool variable to not perform the machine again and send the ball flying through rigidbody force.
Create a new schematic and change the following settings.
Please note that you can arrange the node positions as you like (as long as the connections are the same) – the nodes on the example images are just arranged that way to easily get them on a small screenshot.
Add Node > Game Object > Game Object > Mount Object
We’ll use this node to unmount the ball from the paddle.
Add Node > Value > Variable > Change Variables
We’ll now set a global bool variable that’s used by the machine as condition – otherwise we’d be able to fire the ball again and again.
Click on Add Variable to add a variable change.
Add Node > Game Object > Rigidbody > Rigidbody Kinematic
At first, the ball’s kinematic option is enabled, we’ll need to disable it in order to have it bounce off walls.
Add Node > Game Object > Rigidbody > Rigidbody Add Force
We’ll use this node to add a force to the ball – the force value is stored in a local start variable of the Interaction Machine that plays the schematic.
The X-axis of the force comes from the local start variable initialVelocity.
The Y-axis of the force comes from the local start variable initialVelocity.
The Z-axis should be 0.
And that’s it for this schematic – click on Save Schematic and save it as Ball in Assets/Schematics/.
Next, we’ll add the Paddle schematic (moving the paddle) to the Paddle game object in the scene using a Tick Machine.
We’ll stop the player control when the Game Running game state is Inactive – it’ll be set inactive when the player won or lost all lives (game over).
Add a tick machine component to the Paddle game object (e.g. using the component menu: Makinom > Machines > Tick Machine) and change the following settings.
Click on Add Condition, we’ll set up the game state condition here.
In the added Condition 0, we’ll set up our game state condition.
Click on Add Game State.
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.
Finally, we’ll add the Ball schematic (moving the paddle) to the Ball game object (child object of the Paddle) using an Interaction Machine.
Like the previous machine, we’ll stop this machine when the Game Running game state is Inactive. Additionally, we’ll use the ballInPlay global bool variable that marks if the ball has been already fired in a variable condition to prevent the machine from starting again.
Add an interaction machine component to the Ball game object (e.g. using the component menu: Makinom > Machines > Interaction Machine) and change the following settings.
Click on Add Condition again, this time for the variable condition.
In the added Condition 1, we’ll set up our variable condition. We’ll check if ballInPlay is false, otherwise the machine shouldn’t start.
Click on Add Variable to add a variable condition.
The Machine Start Variable we’ve set up in the schematic is automatically added here with its default value. Make sure the variable is enabled.
And that’s it for now – apply the changes to the Paddle prefab by clicking on Overrides > Apply All (top of the inspector of the Paddle game object).
Hit Play to test the game. You can now move the paddle left and right (until the walls) and shoot the ball once by pressing the Fire key (space). Not much happening yet …
The next tutorial will handle the bricks.