Augmented Reality Tutorial for Beginners With Vuforia and Unity 3D

by matthewh8 in Circuits > Art

61747 Views, 54 Favorites, 0 Comments

Augmented Reality Tutorial for Beginners With Vuforia and Unity 3D

5779d683937ddb1afe0015f8.jpeg
mazeTracker.jpg

This tutorial shows you how to make an augmented reality app in Unity 3D with Vuforia. The game is an interactive ball maze that can be built to Android or IOS. It utilizes the front facing camera to track an image target. This video also goes through how to build the app for Google Cardboard so the game can be played with virtual reality headsets.

Print the picture of the maze above, that will be the image target that your camera is going to track. I made the image target black and white so if you're out of colored ink like me, don't worry.

Create a developer account on Vuforia and add the above picture to your image target database. Download a copy of the database for Unity 3D as well as the Vuforia plugin for Unity.

www.Vuforia.com

Download Unity3D if you don't already have it and make sure to add the modules for Android or IOS depending on what you want to build to.

www.Unity3D.com

Set Up the Scene.

Screen Shot 2016-07-03 at 10.51.26 PM.png

Import the Vuforia plugin and your image database into Unity.

In the Vuforia folder, click and drag the ARCamera prefab into the hierarchy.

Find the imageTarget prefab in the same folder and drag it into the hierarchy as well.

In the scene, move the imageTarget prefab away from the camera by a few units.

Drag it onto the ARCamera prefab (making it a child).

Using cubes create a 3D copy of the maze on top of the image target.

Make a small sphere and create a new material.

Drag the new material onto the sphere and make it a bright color.

Almost Done...

Screen Shot 2016-07-03 at 11.05.35 PM.png

Create a cube and place it above the maze (this is going to be the spawn point for the sphere).

Remove the mesh renderer and collider of the sphere.

Add a C# script to the sphere, call it "ballScript" and paste this code:

using UnityEngine;
using System.Collections;

public class ballScript : MonoBehaviour {

	public GameObject plane;

	public GameObject spawnPoint;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {

		if (transform.position.y < plane.transform.position.y - 10) {

			transform.position = spawnPoint.transform.position;

		}
	}
}

Ready to Build.

Screen Shot 2016-07-03 at 11.06.25 PM.png

In the scene view, click the sphere, and on the ball script, drag the plane and the cube into their respective places.

In the hierarchy, drag the plane, the sphere, and the cube on top of the image target to make them children.

Click play and all should be well.

Now you are ready to build for Android or IOS.

If you want to build for Google Cardboard, click the ARCamera in the hierarchy and go to Digitial Eyewear Behavior Script in the inspector. Choose video see through -> Vuforia -> Cardboard V1. Now you have both stereo cameras and when you build to Android or IOS the app will work in your virtual reality headset.

Any questions don't hesitate to ask. Watch the video for more complete instructions.

Let me know in the comments if you have any requests for future videos.