Game Toolkit for Unity
Setting up the background animations.
In this tutorial we’ll create schematics to animate the background – spawning buses, cabs and swans – and set them up in the scene.
First, we’ll set up the schematic spawning background objects. The objects will move through the background from one side to another, either starting left or right. The schematic will handle a single object and will be used for each background object we’ll be using individually.
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
We’ll add a prefab resource – the used prefab will be set by resource overrides in the machine.
Click on Add Prefab Resource to add a prefab resource. No additional settings needed here.
Add Node > Base > Wait
First, we’ll wait for a random time – the min/max values of the random wait time are stored in local start variables.
Add Node > Base > Chance
We’ll use this node to have a 50 % chance of spawning the prefab left or right.
Add Node > Game Object > Spawn Prefab
We’ll use this node to spawn the prefab on the right side.
This node is connected to the Failed slot of the Chance node.
The Y-Axis is stored in a local start variable.
The Z-Axis will just be set to 0.
Add Node > Game Object > Rigidbody > Rigidbody Change Velocity
We’ll use this node to move the spawned prefab to the left side.
Add Node > Game Object > Prefab > Spawn Prefab
We’ll use this node to spawn the prefab on the left side.
This node is connected to slot 0 of the Chance node.
Copy the previous Spawn Prefab node and change the following settings.
Add Node > Movement > Movement > Change Scale
We’re moving from left to right, i.e. we need to flip the sprite by inverting the scale.
The X-Axis will use the negated X-axis scale.
The Y-axis will just use the Y-axis scale.
The Z-axis will just use the Z-axis scale.
We’ll use this node to move the spawned prefab to the right side.
Copy the previous Rigidbody Change Velocity node.
That’s it for the schematic – click on Save Schematic and save it as BackgroundPropSpawner in Assets/Schematics/.
Next, we’ll create the schematic that will destroy a spawned background object when it moves outside of the level’s area. This schematic will be added to the background objects using a tick machine.
Create a new schematic and change the following settings.
Add Node > Movement > Movement > Check Transform
We’ll use this node to check if the game object’s X-axis position is within a defined range. If not, we’ll destroy the game object.
Add Node > Game Object > Game Object > Destroy Object
We’ll use this node to destroy the game object.
This node is connected to the Failed slot of the Check Transform node (i.e. the game object is outside the defined area).
And that’s it for the schematic – click on Save Schematic and save it as BackgroundPropDestroyer in Assets/Schematics/.
Now, we’ll add the schematic to the background object prefabs. The settings are the same for all prefabs (Bus, Cab and Swan), so you can either repeat the setup or copy/paste the component. The prefabs can be found at Assets/Tutorial Resources/Prefabs/Environment/.
Add a tick machine component to the prefabs (e.g. using the component menu: Makinom > Machines > Tick Machine) and change the following settings.
That’s it for the background prefabs – we don’t need to apply the changes, since we worked directly on the prefabs.
Finally, we’ll set up the auto machines spawning the background objects. We’ll add them to the 3 child objects (busCreator, cabCreator and swanCreator) of the backgroundAnimation game object in the scene. The settings are the same for all 3 prefabs (except for some details), so either repeat the setup or copy/paste the component.
Add an auto machine component to the prefabs (e.g. using the component menu: Makinom > Machines > Auto Machine) and change the following settings.
Expand the Resource Overrides to change the used prefab.
Click on Add Prefab to add a prefab that will be used.
Click on Add Variable to add a start variable.
Copy the previous variable and change the following settings.
And that’s it – don’t forget to save the scene.
Click on Play to start the game. You’ll now see a bus, cab or swan moving from one side to another from time to time.
This concludes the 2D platformer game tutorial series. You can add additional content to the game, e.g. new levels, bigger bombs (increasing the radius) or better health crates (giving more healthBonus).
© 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!