Tuesday 7 January 2014

Boolean Puzzles

Today I set up a small puzzle involving Boolean variables. It consists of rotating wheels in the right position. It is simple and silly, but it is the base for other puzzles.

The Setup:
Boolean puzzle

The setup used in this puzzle is simple: 3 meshes, 3 lights, 3 triggers and a wall. I used the StaticMesh'HU_Deco3.SM.Mesh.S_HU_Deco_SM_VentWheel01' and scaled it up, but you can use any static mesh you want. Also, after placed it has to be converted to a Mover. Then I placed a point light, converted it to a Toggleable light and altered its Radius, Colour, Brightness and unchecked the Enable square. Next the trigger were placed and I altered slightly its size to make it easier for the player to activate it.

Light Properties

Matinee:

The animation was simple, I simply spun the wheel a little bit. You can check the steps for making an animation here. 
Matinee activation code

Kismet: 
After you've set up the matinee sequence, create 3 bool variables(shortcut B+LMB) and name them wheel 01,02 and 03. Then you'll need a Switch node connected to the end of the matinee. In the Switch node properties, you can change the link content to as many as you want. This means that the rest of the sequence will only be activated after the 2nd time it's pressed in the example below. Also check the Looping square, this will reset the counter after the number of links is surpassed.

Bools and Switch Properties
The next step is to toggle the light on and off. Set a Bool variable(NewAction->SetVariable->Bool) and link it to one of the Switch node links. Then create a new named variable(shortcut N+LMB), change FindVarName to the 1st wheel bool object(Wheel01) and set is as the target. On the value end of the Bool, right click and create a new bool object and set its value to 1(true). Link the end of that Bool variable to a Toggle node on the turn on end. When creating the Toggle node don't forget to set the correct light as your target! You can also play an announcement with a text and/or sound to warn the player the wheel is in the right place. For the announcement to work you need to have a game mode set.

You will repeat the Bool node creation process but this time the Boolean object value will be 0(false) and it will be linked to the turn off end of the Toggle node.
Note: The false Bool variable node will be linked to the Switch node just after the true bool node. In this example I linked the true one to link 2 and the false one to link 3.
Toggling light on/off

 That is all you need to make it work. Now you can copy and paste it for the other two wheels. Don't forget to make the adjustments changing the trigger, named variables, lights and wheel object in the matinee sequence.
Code repeated 3 times


With the 3 wheels set, one final code can be added to add more functionality. Creating a Remote Event(shortcut R+LMB) that will be triggered after all 3 wheels are in the right place, this can be a door opening, the end of a level or anything you want. Link the Activate Remote Event Node after the true Boolean Variable node for each wheel.

Activating a remote event

Then on the Remote Event, create a Compare Bool node, set all three named variables to be compared and the Result must be True. In this example, an announcement is made telling the player that all wheels are in the right place.

Comparing bools

This type of "Puzzle" is used a lot in adventure games, where the player must find a certain amount of items to open a door. You can also add other indicators, such as a light with a different colour to indicate the wheel is in the wrong position.

No comments :

Post a Comment