World Effects With Target Tracking

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.

Getting started

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:

  • A 3D object - star, a simple 3D shape. You’ll make this 3D object appear when the camera is pointed at the target image.
  • A texture named SparkTargetPoster. This will be used to create the target image that will trigger the effect.
  • Default environment texture - an environment texture applied to the 3D object to create a realistic lighting effect.

Adding a target tracker

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:

  1. Click Add Object.
  2. Select Target Tracker from the menu.

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:

Adding the target image

Next add the target image to the target tracker:

  1. Select the TargetTracker0 in the Scene panel.
  2. Go to the Inspector.
  3. To the right of Texture, click the dropdown and select SparkTargetPoster.

Choosing a good target image

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.

Adding the 3D object

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:

  1. Select Star in the Assets panel.
  2. Drag it onto targetTracker0 in the Scene panel.

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:

  1. In the Scene panel, select Star.
  2. In the Inspector, go to Scale and change the X, Y and Z values to 3.

Fixed or moving targets

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:

  • Moveable - the effect will move with the target image if the target image changes position. If the camera isn’t pointing at the target, the effect will disappear.
  • Fixed - The effect will stay in the position of the target image when it was first detected by the camera, even.

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.

Testing target tracking

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.

Was this article helpful?