Ever wonder how to us the ARKit Plugin to interact with objects that are in your room? Keep reading to find out!

Interacting with objects in the scene is vital to the gameplay for our augmented reality app Escape The Room. Hopefully this article helps you jump your AR development!

This article contains a bit of a code, and bit on how to set everything up in the scene. To start, you’ll need need to get the object you want to use and at it to the scene.

A simple object in the scene.

There are a few things you’ll need to do to this object to make it tappable. The first is to add a Mesh Collider or Box Collider component to your game object. A Box Collider is more efficient for the system, as it doesn’t have to do extra calculations to fit the collider to the mesh of the object, but in this case the object is very simple, and the scene that this object is in isn’t too intense so a Mesh Collider will be fine.

The Mesh Collider has been added!

This will allow us to cast a ray and interact with our object!

You might have noticed something else in that screenshot, we have added a tag for our object called ‘altarPyramid’.

Without a tag on the object, you won’t know which object you’re tapping! Make sure you add this, its an easy step to forget! Now its time for some code!

The Code

You’ll need to create a script and at it to your scene because all the code we’ll be dealing with occurs in the Update function, which gets called every frame.

That’s it!

Above is the code, and its pretty straightforward! Every frame, you detect if there is a touch in the scene.

If there is a touch, and the touch just began, create a ray and cast it out based on where the user tapped in the scene.

If the raycats detected a hit, read the tag that we set up earlier. If the tag is equal to the one we set up earlier, we succesfully touched our object!

Our tappable pyramid! Plus a little preview of some in game features!

We’re in the very early stages of AR, and the more devs the merrier. I hope this tutorial helped, and please reach out to help grow our community!