The Head Tracker functionality detects an onscreen head and provides information about the 3D position of the head in virtual space. This is a robust and widely-used functionality that allows you to add 3D objects to the head and face.
This example puts a sphere on the onscreen head’s nose that stays in place using the head tracker! First we’ll talk about how to add head tracking capability and go over the initial setup. Then we’ll add our sphere and make some tweaks to finish the effect.
Add a head tracker
First, we have to add a Head Tracker entity. We can do this by clicking + Add Object > AR Tracking > Head Tracker. A Head Tracker will then be added to the scene hierarchy.
Add and track a sphere
Now let’s add our sphere entity! Navigate to the Hierarchy panel and click + Add Object > 3D > Sphere . We will add a built-in sphere to our scene.
Now we can see a preview of our effect thus far in the Preview window. By default, the sphere is not actually tracking with the onscreen head.
To ensure that the object follows the head, we need to parent the sphere object under the Head Tracker. This way, it will follow head movement.
Change placement and add material
Now we can see that our sphere is following the head onscreen, but let’s make it a little more interesting!
First, we’ll move and scale our sphere to track with the nose.
Next, we’ll need to create a new material for our sphere. Navigate to the Assets panel and click + Add Asset > Material > Standard PBR.
Let’s change the color of our new material from the default gray to something new! Select the Standard PBR material from the Assets panel to bring up its parameters.
For our material, we will be changing the base color in the Albedo section. For this guide we will make the material pink, but you can use whatever color you like!
Now we can apply the material to our sphere! Select the sphere in the Hierarchy and navigate to the Mesh Renderer listed in its components. We can apply our Standard PBR to the Material section.
Now we can see the final result in the Preview panel!
Head tracker properties
The Head Tracker entity will follow a head that is detected in the scene. Select the Head Tracker from the Hierarchy in order to bring up its parameters in the Inspector. Here we can see the Face Binding which determines the functionality of the tracking mechanic.
Face Binding properties
- Anchor: This parameter determines on which specific part of the target to focus. We will be using Face Center for head tracking.
- Which Face: This parameter determines who this tracker will follow in the case of multiple faces onscreen. We can detect up to 5 faces at a time, and we must create and assign a Head Tracker for each face we want to track.
The face number assignment is based on the order of detection. The first face detected in the scene will be assigned to Face 1 and so on.
By default, adding a Head Tracker will add two items to the hierarchy.
The Head is parented under the tracker object so that it follows. It is a head-shaped mesh with an occluder material that will allow us to mask out the onscreen head.
With the occluder material, the head model can be used to occlude other 3D objects in the scene. For example, if a hat model wraps around the head, we can occlude the back of the hat so that it appears to be sharing the same 3D space as the head onscreen.
You can download the head model for 3D scale reference here: