This Motion Tracking How-to guide will get you up and running with a simple Motion Tracking application in Unity. The instructions are intended for Unity developers of any experience level. You'll add a Tango-enabled camera, and then build a simple scene. When you launch your app and then walk around in your environment, the device's motion moves the camera around in the Unity scene.
If you haven't set up your computer to develop with Tango in Unity yet, see Getting Started With Unity.
Go to the Setup for All Unity Tango Apps page and perform the basic setup operations on that page. When you have finished, return to this page and continue on with the steps below.
Add the Tango Delta Camera prefab to your Hierarchy
If you want to learn more about prefabs, see the Unity documentation.
- In the Project panel, click TangoPrefabs to view the contents of that folder.
- Drag the Tango Delta Camera prefab (frustrum icon) to the Hierarchy panel.
- Select GameObject > 3D Object > Cube.
- From the same menu, add a Plane and a Sphere gameObject.
Adjust the positions of the gameObjects
Adjust the positions of the following gameObjects by changing their Position (XYZ) values. These values are found in each gameObject's Transform component. Change each gameObject as follows:
- Cube: position = 3,1,0.
- Sphere: position = 0,1,3.
- Tango Delta Camera: position = 0,1,0.
The default values of the plane and directional light will work fine. Here they are in case you'd like to confirm them:
- Plane: position = 0,0,0.
- Directional light: position = 0,3,0.
Your scene should look something like this:
Build and run your project
- On the File menu, click Build and Run.
- In the Build Settings dialog, click Build and Run.
- In the Build Android dialog, enter a name in the Save As field, and then click Save.
Experiment with your app
Hold your device up to eye level. You should see the sphere. Start to walk around, and note that your movement in the real world is duplicated in the virtual world of your app. Walk to the left and right of the sphere, and behind it. If you tilt your device back and forth and move it around enough, you'll eventually see the cube.
Disable the Trail Renderer (optional)
As you move around with your device, a blue line is drawn along its path in 3D space. This line is drawn by a child of the Tango Delta Prefab called Trail. If you don't want to display the line, here's how to disable it:
- In the Hierarchy panel, expand Tango Delta Camera to show its children, and then click Trail.
- In the Inspector panel, deselect the Trail gameObject.
Build and run.