This is part 4 of the AR Scavenger Hunt Series
It’s time to bring our scavenger hunt to life!
Tip: If you’re new to Lens Studio, checkout this quick start guide which provides handy links you might need to get around Lens Studio.
Once you open the project, you’ll notice the whole project is mostly controlled by 2 kinds of scripts, Stage Controller and Stage Script.
The StageController object has a list of Stage Scripts as input, every slot in its Stage Scripts list needs to have an object with the Stage Script attached. The stage controller will run through each script based on their order in the Stage Scripts list.
The Stage Script is the fundamental block of the scavenger hunt template. This script defines how each puzzle is played out. You can find out objects with stage scripts under the object Stages [EDIT_CHILDREN].
Each Stage Script has a Trigger Type. The trigger set here will be the way to complete this stage. It could be scanning a marker, checking distance between 2 objects, having a smile, or triggered by the completion of multiple stage scripts.
Each stage also has a Hint section, enabled by checking the HasHint boolean.
Each Hint Object will be enabled when this stage is started, and disabled when this stage is completed. The hint object will be toggled by running a tween to fade in and out. Make sure the tween scripts attached to the Hint Object has the correct name and is set to recursive.
Tip: Learn more about Tweens in the Tween guide.
Setting up your Scavenger Hunt
Let’s create something fairly straightforward with simple instructions, such as a scavenger hunt on paintings and other random images at home. We’ll first go around and see what are some of the images we can use as ‘markers’.
For a good image marker, we’d want it to be flat and visible. If you have a dog or cat at home we can also use them as markers (by using the Cat/Dog tracking feature in Object Tracking).
Then we’d take a flat image of these markers, make sure to have these images be as flat and squared as possible, such as this:
Once you got your markers images ready, import them by selecting Objects → Object Tracking → Image Tracking
Then in your Stage Script, select Scan Marker as Trigger Type then input the marker.
Now this stage will be completed once this marker has been scanned. We’ll also add a custom hint to it. Create your hint object, it could have texts and images on it, make sure the hint object has correlated tween setup.
Then, input this object in the HintObject slot on the Stage Script.
Repeat the same step for all other markers. The hint can be straightforward, or funky and confusing, feel free to go wild but be careful to not confuse your players too much ;)
This is what our project looks like after we’ve set up everything.
For lucky people with adorable pets at home, we can also set up a dog/cat tracking trigger. You’ll notice there is no such selection in Trigger Type in Stage Script, but we can use a Custom Trigger with Behavior script to set this up.
Tip: Behavior provides easy access to many different capabilities in Lenses--take a look at the Behavior guide for a complete list of what you can use as triggers
We’ll first create a Behavior object from the Objects panel, and move this object all the way to the top so that it’s available for any of our stages.
Then we’ll create a Dog (or Cat) Tracking element from the Objects panel as well. We’ll input that as the Trigger in our Behavior script, and have Behavior send out a global trigger with a specific name as its response. In this case we’ll use the name DOG_FOUND.
Then we’ll use the same trigger name in our Stage Script:
Putting it Together
Now that we have each stage of our scavenger hunt, let’s connect them together. To do this, we’ll add every stage script to Stage Controller!
Adding Visual Flair
One last thing we can do is add some visual response for when each stage is completed. For this example, we can set up particles to be played by a function in a custom script, make sure the api function is called onResponse.
Then in each Stage Script object, input the Particle Confetti objects in the Api to Call On Complete section.
Now after each stage has been completed, there will be confetti particles popping out from the bottom of the screen!
The final important piece of making a game is of course, play testing--this is important to make sure that not only the Lens works technically as you expect, but again whether or not the game is fun!
For example, below we’ll see our hint show up at the beginning of each stage, and particles come out once we’ve located the correct marker, then the hint message for the next marker would fade into the screen.
Human’s best friend!
That’s it for this tutorial! Hope you’ll enjoy creating with the scavenger hunt template, and please do not hesitate to share your creations on the Lens Studio forum!
Click here to download the example scavenger hunt project.
Designing an AR Scavenger Hunt