With target tracking world effects, an augmented reality effect is triggered when the camera is pointed at a specific real world target, like a business card or picture.
In this tutorial, you'll create a target tracking world effect that makes an object appear when the camera is pointed at a Spark AR Studio poster.
Download the sample content to follow along. It includes both the finished project and an unfinished version.
To get started, open the unfinished effect in the sample content folder. We’ve already imported the objects and assets you’ll need — they’re listed in the Assets panel. You’ll see:
The foundation of any target tracking world effect is an object included in Spark AR Studio called a target tracker. This object detects the real life target, triggering an effect in response.
To add a target tracker:
It’ll be listed in the Scene panel as TargetTracker0. You’ll also see a square in the middle of the Viewport and Simulator. This square represents the space for the target image:
Next add the target image to the target tracker:
Not all target images are easily detected by the target tracker. A poor target image might not trigger your effect consistently, or at all.
When you’ve added a target image to the target tracker, check the Target Tracking Confidence feature in the Inspector to see whether your target image will work well or not:
Depending on how good to target is, you’ll see either a Good or Poor readability score across 3 different device types.
Flat target images like posters or business cards work best for target images, making the clearest image for the target tracker to detect. Take a look at these examples of good and bad target images to help choose something that will work well.
Any objects added as children of the target tracker will appear when the camera is pointed at the target image.
For this tutorial, add the star 3D Object:
Here’s how the star object will appear in the Scene panel, Viewport and Simulator:
The 3D object is a little small. To make it bigger:
Target tracking effects can either stay in the place where the camera first detected the target image, or move with the target image as it changes position. This is determined by the Target Type property in the Inspector. When set to:
If the target image is moved. When the camera moves, the effect will stay in its original position and be visible again if the camera is pointed back in that direction.
The default setting is Moveable, which we’ll keep for this effect.
Use Spark AR Player to test the effect. You’ll need to print out the Spark Poster target — find it in the sample content file under Textures.
Change someone’s environment with segmentation and the camera texture.
Position rectangles a texture to create a frame that scales with the device screen.