Creating a Location-Based Christmas AR Experience in Less Than 10 Minutes

There is certainly a lot of hype around AR nowadays, specially with the advent of the ARKit/ARCore duo — which allows you to easily build augmented-reality experiences on iOS and Android devices.

Still, the directions one should take to build successful AR products is less clear — as it usually is with novel technologies. Gaming? Education? Business? Technical Materials? All Of The Above?? If I were to guess today I would say education, training and technical-focused corporate software is were it’s at.

In any case, there is still a lot to be done so that AR experiences are ever so integrated in the real world. Work on 3D object occlusion, realist lighting, better and more intuitive AR user interfaces, are all essential aspects of this development.

One other, in which I am passionate about making a contribution, is integrating AR with real-world locations via their geographic (or GPS) coordinates¹. This is often called Location-Based Augmented Reality.

Anyone who has to deal with location data from mobile devices knows how hard it can be to work with such data, and cam imagine the challenges that there are in trying to continuously synchronize the real and the virtual world using it (I will go in depth about them in a future post). Luckily, we can get some help from the Visual-Intertial-Odometry implemented in modern AR systems ; )

While working on these issues I developed and recently release an Unity3D scripting plugin called AR+GPS Location. You can check it at the Unity Asset Store here, and it’s full documentation here.

Since it’s Christmas time, I wanted to build something cool to show the kids in our family. So I got myself some Christmas-themed 3D assets from cgtrader, fired-up the Unity3D editor and, using the AR+GPS Location package, created a AR Christmas experience in about 10 minutes. Here is how.

First

Get some cool models you want to see in the real-world : )

I got this pack at cgtrader at a good price and I really liked it. Best of all, it contained a pre-packaged unity project, so I had to do was import it and all the 3D assets were almost done!

All that is need to do is to move around the objects to build what you’d like to. In my case, I built a Santa Claus riding his Sled, dragged on by his loyal reindeer. What I got was this:

And, adding some quick-and-dirty particle systems, this was the final result:

Second

Add some motion.

So far it looks OK, but it’s a little boring. Let’s put some more life into it.

Let’s say the reindeer do some type of wavy motion while the sled flies about it’s way. The simplest thing we can do is to make them oscillate in the y-direction, using a sinusoidal function.

To do that, I created a MoveDeers script component with the following code

Just add the component, and here we have it.

Third

Setup the scene for AR Foundation.

Start by importing the AR Foundation and the ARKit or ARCore (depending on the platform you are targeting) packages via the package manager.

And the AR+GPS Location package from the Unity Asset Store.

Now let’s create the basic structure for a AR Foundation scene. That means we need to have two objects at the root of the scene: one AR Session object, with a AR Session component, and one AR Session Origin object, with an AR Session Origin component.

We also need to parent the main camera to the AR Session Origin object, and two components to it: A TrackedPoseDriver component, and a AR Camera Background component. Don’t forget to set the Pose Source in the TrackedPoseDriver component to Color Camera.

Fourth

Setup the scene for AR+GPS Location!

We’ll also need some additional objects and components.

First, a LocationProvider object with a LocationProvider component:

This component manages location data and controls how often we update the data and how accurate we (ideally) want it to be. Play around with the values to see which ones work better for your project.

Next, we’ll create an object named ARLocationRoot under the AR Session Origin object and add two components to it, a ARLocationOrientation and a ARLocationManager.

The ARLocationOrientation component makes sure that the coordinate system of the ARLocationRoot object is in synch with the cardinal directions, so that to z-axis will match the true north, while the x-axis will point to the east. And the ARLocationManager makes sure all placed objects in the scene are in their correct positions.

Fifth

Let’s make it fly!

We’ll be making santa claus and his sledge move along a predefined geographical route using the ARLocationMoveAlongPath component. With it we can select a set of points we want our object to pass trough in it’s way, choose it’s velocity along it, and that’s it!

To do that we first create a ARLocationPath, which is a ScriptableObject that holds the data describing the path, that is, the geographical coordinates of the set of points.

So let’s get our coordinates! One easy way to do this is to login to Google Maps, go to ‘your places’, then ‘Maps’, and click on ‘Create Map’. Then you can just add draw your path by placing markers, like I did below.

That way you can see the basic shape of the path, and then just click on the points to copy the latitude/longitude coordinates.

Now go back to the Unity editor, and click on Create/ARLocation/Path to create a new Path. Set the number of locations and copy/paste the coordinates from the map. Adjust the altitudes as you wish (they’ll usually be relative to the device’s initial height. We can do absolute altitude from the device’s sensors, but this is usually wildly inaccurate).

Finally, assign the path to the ARLocationMoveAlongPath component in Stanta’s Sled game object and we are ready to go!

Sixth

Compile and enjoy!

You can get the AR+GPS Location package here: https://assetstore.unity.com/packages/templates/systems/ar-gps-location-134882

Full docs here: https://docs.unity-ar-gps-location.com

If you have any questions, just e-mail me at daniel.mbfm@gmail.com, or at twitter @daniel_mbfm.

Thanks for reading this, Merry Christmas and a Happy New Year!

Notes

[1] Of course, we are referring to the WGS 84 geographic system, which is to most widely used geographic coordinate system today. But there are other possible systems one can use.

Computer graphics, code and creativity. danielfortes.com