Setting up schematics for the jewel matching logic.
In this tutorial we’ll create schematics to check if the jewels above, below, left and right of a jewel are matching (i.e. are of the same color). To make it as easy as possible, we’ll find the matching jewels by using a shapecast with additional distance and name checks. In our game, the color of the jewel is in the game object’s name, i.e. we’ll check for game objects having the same name.
First, we’ll create a schematic that checks the nearby jewels. This is done by storing the machine object (executing the schematic) in a global selected data named match. Afterwards, we’ll check the nearby jewels using a shapecast and filters (as explained above) – if something was found, it’ll start this schematic on the found game objects (jewels). This is repeated until no matching jewels are found any longer – at the end, all matching jewels are stored in the match global selected data (which is processed by another schematic we’ll set up afterwards).
Open the Makinom editor, navigate to Schematics and create a new schematic. Change the following settings.
Add Node > Game Object > Game Object > Select Game Objects
We’ll use this node to add the machine object to the match global selected data.
Add Node > Game Object > Raycast > Check Shape
We’ll use this node to check the nearby game objects and filter the found game objects.
The Origin defines the center of our circle cast.
The Radius defines the radius used for the circle cast.
The Layer Mask defines which layers the circle cast will interact with. This sould already be the default setup (using everything).
Click on Add Object Check to add a check. We’ll check for game objects matching the machine object’s name.
Click on Add Distance Check to add a check.
The To Object game object defines which game object will be used for the distance check (beside the one found by the shapecast).
We’ll check for game objects that have a distance of 1 or less to the machine object. We only want the jewels that are above, below, left or right of the jewel we’re currently checking – they have a distance of 1 (since that’s how we set up our grid, but we’ll check for 1.1 to make sure we don’t miss anything due to rounding). Without this check, we’d also get the jewels diagonally to the jewel.
Click on Add Excluded Object – we’ll exclude the already found matches to prevent checking the same game objects multiple times.
We need to remember the game objects found by the shapecast to be able to use them in the next node. We’ll store them in the local selected data check – local selected data is only available in the running schematic.
Before adding the next node, we need to save the schematic – click on Save Schematic and save it as GetMatches in Assets/Schematics/. Otherwise we wouldn’t be able to use the schematic in itself.
Add Node > Machine > Start Machine
We’ll use this node to start this schematic on all found game objects.
This node is connected to the Success slot of the Check Shape node.
And that’s it for this schematic – don’t forget to save the changes.
Next, we’ll create the schematic that initates checking for the matching jewels. It’ll first check if the machine object (jewel) is already marked to be destroyed (due to matches) – if not, it’ll start the Get Matches schematic we just created. After Get Matches finished executing, we’ll have neighbouring matches stored in the global selected data match – all we need to do is check if 3 or more jewels match and mark them for destruction.
Create a new schematic and change the following settings.
Add Node > Game Object > Game Object > Selected Game Objects Contain
We’ll use this node to check if the machine object is already marked for destruction – i.e. stored in the global selected data destroy.
In case the object isn’t stored in the global selected data destroy, we’ll start the Get Matches schematic on it.
This node is connected to the Failed slot of the Selected Game Objects Contain node.
Add Node > Game Object > Game Object > Selected Game Objects Count
We’ll use this node to check if the found matches (global selected data match) are 3 or more.
In case 3 or more matches are found, we’ll add the matches to the global selected data destroy.
This node is connected to the Success slot of the Selected Game Objects Count node.
Add Node > Value > Selected Data > Clear Selected Data
We’ll use this node to remove all data from the global selected data match to be ready for the next match check.
This node is connected to the Failed slot of the Selected Game Objects Count node and the Next slot of the previous Select Game Objects node.
And that’s it for the schematic – click on Save Schematic and save it as CheckJewel in Assets/Schematics/.
The next tutorial will handle destroying jewels.
© 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!