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 Meta Spark 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. You'll find all the objects and assets you need. 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 Meta Spark Studio called a target tracker. This object detects the real life target, triggering an effect in response.

To add a target tracker:

  1. Click + in the Scene panel.
  2. Select Target Tracker from the menu.

It’ll be listed in the Assets 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:

A checkerboard patterned rectangle can be seen in the center of the Simulator.

Adding the target image

Next, add the target image to the target tracker:

  1. Select TargetTracker0 in the Scene panel.
  2. Go to the Inspector.
  3. To the right of Texture, click the dropdown and select SparkTargetPoster.
The texture that we will use for a target image is being selected in the Inspector.

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.

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 to help choose an image 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. In the Scene panel, select Star.
  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 effect has been triggered, and is shown in the 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.

  • 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 move.

The default setting is Moveable.

Testing target tracking

Use Meta Spark Player to test the effect. You’ll need to print out the Spark Poster target — find it in the sample content file under Textures.