Setting up the schematic handling the game controls.

In this tutorial we’ll create the schematic that handles the game controls. The controls are simple – you click on a jewel to select it (shown through blinking), clicking on a jewel above, below, left or right of the selected jewel will swap them. If at least one of the swapped jewels has 3 or more matching jewels (found by the schematics we set up earlier) at the new position, we’ll destroy them, resulting in the jewels above falling down and new jewels being added to the empty cells.

It might sound complicated and involve a lot of nodes – but the actual schematic is pretty straight forward. For better understanding, we’ll split the selection (blinking) and matching/destroying parts of the schematic on 2 different layers. The schematic will be played by an Interaction Machine (using mouse click) on the individual jewels.

Jewel Click: Schematic

Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.

Settings

We need a prefab resource for handling our random jewels for filling empty cells after jewels have been destroyed (and moved down).

Prefabs

Click on Add Prefab Resource to add a prefab resource.

  • Name
    Set to Jewel.
  • Use Order
    Select Random.

We need 5 prefabs in this prefab resource, add the needed amount by clicking on Add Prefab.

  • Prefab
    Select bluegreenpurplered and yellow.
    The prefabs can be found at Assets/Tutorial Resources/Prefabs/.

Selected Game Objects Count

Add > Game Object > Game Object > Selected Game Objects Count

First, we’ll check if the player already selected a jewel by checking if the global selected data clicked is empty.

  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Check Settings

  • Check Type
    Select Is Equal.
  • Value
    Set to 0 (Value).

Select Game Objects

Add > Game Object > Game Object > Select Game Objects

No jewel has been selected, so we’ll add the machine object (i.e. clicked jewel) to the global selected data clicked.

This node is connected to the Success slot of the previous Selected Game Objects Count node.

  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.
  • Change Type
    Select Add.

Game Object

  • Object
    Select Machine Object.

Change Color

Add > Game Object > Renderer > Change Color

We’ll start blinking the selected jewel.

  • Color Type
    Select Renderer.
  • Fade
    Select Blink.
  • Wait
    Disable this setting.
  • Time (s)
    Set to 0.25 (Value).
  • Fade Alpha
    Enable this setting.
  • Fade Red/Green/Blue
    Disable these settings.
  • From Current
    Enable this setting.
  • End Color
    Set to R=0, G=0, B=0, A=100.

Game Object

  • Object
    Select Machine Object.

Change Sorting Layer

Add > Game Object > Renderer > Change Sorting Layer

We’ll use this node to make sure that the selected node is above other nodes when swapping them by changing it’s sorting order to 1.

This ends the jewel selection (i.e. the player clicked on a jewel without having another jewel selected).

Sorting Order

  • Change Sorting Order
    Enable this setting.
  • Sorting Order
    Set to 1 (Value).

Object

  • Object
    Select Machine Object.

Selected Game Objects Contain

Add > Game Object > Game Object > Selected Game Objects Contain

If a jewel is already selected, we need to check if the player clicked the selected jewel.

This node is connected to the Failed slot of the first Selected Game Objects Count node.

  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Game Object

  • Object
    Select Machine Object.

Select Game Objects

Add > Game Object > Game Object > Select Game Objects

The clicked jewel is already selected, so we need to deselect it.

This node is connected to the Success slot of the previous Selected Game Objects Contain node.

  • DataKey
    Set to clicked.
  • Data Origin
    Select Global.
  • Change Type
    Select Remove.

Game Object

  • Object
    Select Machine Object.

Change Color

Add > Game Object > Renderer > Change Color

We’ll stop blinking the selected jewel.

  • Color Type
    Select Renderer.
  • Fade
    Select Stop.

Game Object

  • Object
    Select Machine Object.

Change Sorting Layer

Add > Game Object > Renderer > Change Sorting Layer

We’ll use this node to reset the sorting order of the selected jewel to 0.

This ends deselecting the jewel (i.e. the player clicked on the selected jewel).

Sorting Order

  • Change Sorting Order
    Enable this setting.
  • Sorting Order
    Set to 0 (Value).

Object

  • Object
    Select Machine Object.

Check Distance

Add > Movement > Movement > Check Distance

The player clicked on a jewel while having another jewel selected – we’ll need to check the distance between them to determine if we can swap them. Jewels that can be swapped have a distance of 1 or below (to make sure we don’t miss anything due to rounding, we’ll check for 1.1).

From Object

  • Object
    Select Machine Object.

To Object

  • Object
    Select Selected Data.
  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Check

  • Needed
    Select All.
  • Ignore Y Distance
    Disable this setting.
  • Check Type
    Select Is Less Equal.
  • Distance
    Set to 1.1 (Value).

Gate Entry (Layer Gate)

Next, we’ll add a Layer Gate node to the reach the next layer. This node is connected to the Success slot of the previous Check Distance node.

Right click on the Success slot and select Add > Gate to Layer > Add New Layer. This will create a new layer and add a layer gate to it.

To display the new layer, either double click on the on the node’s title or select it in the layer popup field in the upper right corner of the editor.

You can rename the layer by clicking on the Rename Layer icon right of the popup field – e.g. name the layer Check Nodes. Clicking on the icon again will stop editing the layer’s name.

Change Color

Add > Game Object > Renderer > Change Color

We’ll stop blinking the selected jewel.

  • Color Type
    Select Renderer.
  • Fade
    Select Stop.

Game Object

  • Object
    Select Selected Data.
  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Swap Grid Cell

Add > Game Object > Grid > Swap Grid Cell

We’ll use this node to swap the selected and clicked jewel.

  • Set Position
    Enable this setting.
  • Set Rotation
    Enable this setting.
  • Mount
    Enable this setting.

Grid 1

  • Grid Key
    Set to level.
  • Grid Cells
    Select Single Index.

We’ll use the clicked jewel (machine object) to find it’s index in the grid.

  • Vector3 Type
    Select Grid Object Index.
  • Grid Key
    Set to level.
  • Object
    Select Machine Object.

Grid 2

  • Grid Key
    Set to level.
  • Grid Cells
    Select Single Index.

We’ll use the selected jewel (global selected data clicked) to find it’s index in the grid.

  • Vector3 Type
    Select Grid Object Index.
  • Grid Key
    Set to level.
  • Object
    Select Selected Data.
  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Animation Settings

  • Animate Swapping
    Select Interpolate.
    We’ll move the swapping game objects through interpolating between their positions.
  • Move Time (s)
    Set to 0.3.
  • Wait
    Enable this setting.
  • Interpolation
    Select Ease In Out Quad.

Select Game Objects

Add > Game Object > Game Object > Select Game Objects

We’ll make sure that the global selected data destroy is empty before checking for matching jewels.

  • Data Key
    Set to destroy.
  • Data Origin
    Select Global.
  • Change Type
    Select Clear.

Start Machine

Add > Machine > Start Machine

Now, we’ll check the selected jewel for matching jewels.

  • Schematic Asset
    Select CheckJewel.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.
  • Share Local Variables
    Enable this setting.
  • Wait Between
    Enable this setting.
  • Wait
    Enable this setting.

Machine Object

  • Object
    Select Selected Data.
  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Starting Object

  • Use Same Object
    Enable this setting.

Start Machine

Add > Machine > Start Machine

Next, we’ll check the clicked jewel for matching jewels.

  • Schematic Asset
    Select CheckJewel.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.
  • Share Local Variables
    Enable this setting.
  • Wait Between
    Enable this setting.
  • Wait
    Enable this setting.

Machine Object

  • Object
    Select Machine Object.

Starting Object

  • Use Same Object
    Enable this setting.

Selected Game Objects Count

Add > Game Object > Game Object > Selected Game Objects Count

After checking the jewels, we need to determine if matching jewels where found and marked for destruction by checking the global selected data destroy.

If jewels where found, we’ll destroy them – otherwise we’ll reverse the swap and end the schematic.

  • Data Key
    Set to destroy.
  • Data Origin
    Select Global.

Check Settings

  • Check Type
    Select Is Greater.
  • Value
    Set to 0 (Value).

Swap Grid Cell

Add > Game Object > Grid > Swap Grid Cell

We’ll use this node to reverse the swapping.

This node is connected to the Failed slot of the previous Selected Game Objects Count node.

  • Set Position
    Enable this setting.
  • Set Rotation
    Enable this setting.
  • Mount
    Enable this setting.

Grid 1

  • Grid Key
    Set to level.
  • Grid Cells
    Select Single Index.

We’ll use the clicked jewel (machine object) to find it’s index in the grid.

  • Vector3 Type
    Select Grid Object Index.
  • Grid Key
    Set to level.
  • Object
    Select Machine Object.

Grid 2

  • Grid Key
    Set to level.
  • Grid Cells
    Select Single Index.

We’ll use the selected jewel (global selected data clicked) to find it’s index in the grid.

  • Vector3 Type
    Select Grid Object Index.
  • Grid Key
    Set to level.
  • Object
    Select Selected Data.
  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Animation Settings

  • Animate Swapping
    Select Interpolate.
  • Move Time (s)
    Set to 0.3.
  • Wait
    Enable this setting.
  • Interpolation
    Select Ease In Out Quad.

Change Sorting Layer

Add > Game Object > Renderer > Change Sorting Layer

We’ll use this node to reset the sorting order of the selected jewel to 0.

Sorting Order

  • Change Sorting Order
    Enable this setting.
  • Sorting Order
    Set to 0 (Value).

Object

  • Object
    Select Selected Data.
  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Clear Selected Data

Add > Value > Selected Data > Clear Selected Data

We’ll clear the global selected data clicked to deselect the jewel.

This node is also connected to the Failed slot of last Selected Game Objects Count node we’ll add afterwards (checking if destroying and moving jewels caused new matches).

  • Data Key
    Set to clicked.
  • Data Origin
    Select Global.

Change Variables

Add > Value > Variable > Change Variables

Swapping the jewels resulted in matching jewels – we’ll use this node to increase the player’s turns.

This node is connected to the Success slot of the previous Selected Game Objects Count node (checking if swapping the jewels resulted in matching nodes marked for destruction).

Click on Add Variable to add a variable change.

  • Change Type
    Select Variable.
  • Variable Key
    Set to turns.
  • Variable Origin
    Select Global.
  • Type
    Select Int.
  • Operator
    Select Add.
  • Float Value
    Set to 1 (Value).

Start Tagged Machine

Add > Machine > Start Tagged Machine

We’ll use this node to start tagged machines on the jewels we’re going to destroy.

  • Share Local Variables
    Enable this setting.
  • Wait Between
    Enable this setting.
  • Wait
    Enable this setting.
  • Single Execution
    Disable this setting.

Machine Object

  • Object
    Select Selected Data.
  • Data Key
    Set to destroy.
  • Data Origin
    Select Global.

Starting Object

  • Use Same Object
    Enable this setting.

Tag Settings

  • Needed
    Select One.

Click on Add Tag to add a starting tag.

  • Tag
    Set to destroy.

Clear Selected Data

Add > Value > Selected Data > Clear Selected Data

We’ll clear the global selected data destroy, making it ready for the next match checking.

  • Data Key
    Set to destroy.
  • Data Origin
    Select Global.

Move Grid Cell

Add > Game Object > Grid > Move Grid Cell

We’ll use this node to move all jewels down, if they have empty cells below them – and repeat this until no jewel can move any longer.

Index Change

  • Vector3 Type
    Select Direction.
  • Direction
    Select Down.

We’ll only move assigned cells (i.e. cells that have a jewel) to empty cells. We don’t need any looping.

  • Moving Cells
    Select Assigned.
  • Target Cells
    Select Empty.
  • Set Position
    Enable this setting.
  • Set Rotation
    Enable this setting.
  • Mount
    Enable this setting.
  • Destroy Current
    Enable this setting.

Repeat Movement

  • Repeat Move
    Select Until All Unmovable.
  • Wait Between
    Enable this setting.

Grid Settings

  • Grid Key
    Set to level.
  • Grid Cells
    Select Whole Grid.

Animation Settings

  • Animate Swapping
    Select Interpolate.
  • Move Time (s)
    Set to 0.1.
  • Wait
    Disable this setting.
  • Interpolation
    Select Linear.

We’ll store the game objects that actually moved in a local selected data to check them afterwards for matches.

  • Change Selected Data
    Enable this setting.
  • Data Key
    Set to moved.
  • Data Origin
    Select Local.
  • Change Type
    Select Set.
  • Use Hidden Cells
    Disable this setting.

Fill Grid Cells

Add > Game Object > Grid > Fill Grid Cells

We’ll use this node to fill all empty cells with new jewels. Since we moved jewels down on the empty cells, the new jewels will only be added in the hidden part of the grid.

  • Prefab
    Select Prefab 0: Jewel.
  • Fill Mode
    Select Empty.
  • Mount
    Enable this setting.
  • Destroy
    Enable this setting.

Grid Settings

  • Grid Key
    Set to level.
  • Grid Cells
    Select Whole Grid.

Start Machine

Add > Machine > Start Machine

Now, we’ll check the moved jewels for matching jewels.

  • Schematic Asset
    Select CheckJewel.
  • Execution Type
    Select Single.
  • Update Type
    Select Update.
  • Share Local Variables
    Enable this setting.
  • Wait Between
    Enable this setting.
  • Wait
    Enable this setting.

Machine Object

  • Object
    Select Selected Data.
  • Data Key
    Set to moved.
  • Data Origin
    Select Local.

Starting Object

  • Use Same Object
    Enable this setting.

Selected Game Objects Count

Add > Game Object > Game Object > Selected Game Objects Count

After checking the moved jewels, we need to determine if matching jewels where found and marked for destruction by checking the global selected data destroy.

If jewels where found, we’ll return to destroy them – otherwise we’ll clear the global selected data clicked and are done.

This node’s Success slot is connected to the Start Tagged Machine node destroying the jewels, the Failed slot is connected to the Clear Selected Data node clearing the clicked game objects.

  • Data Key
    Set to destroy.
  • Data Origin
    Select Global.

Check Settings

  • Check Type
    Select Is Greater.
  • Value
    Set to 0 (Value).

And that’s it for the schematic – click on Save Schematic and save it as JewelClick in Assets/Schematics/.

The next tutorial will handle setting up the jewels.