Getting a closer look and Putting our Object back

Miguel Pacheco
3 min readFeb 3, 2024

--

In my AR app I want to be able to get a closer look to examine the object selected and put it back to it’s original position when unselected.

I’ve created a cube prefab to use as the placement interactable prefab.

This cube has an AR Selection Interactable component that is going to let us know that we’ve selected the cube.

I created a game object as a child of the main camera to set the cube position to this new game object position. I also need to set the new game object as a parent of the cube so the cube can follow the camera. All of this is going to happen when we select the cube.

Let’s create some C# Scripts to make this possible.

I’ll create a script for the cube that will contain two public functions. One to examine the object and one to unexamine the object.

I created another C# Script and name it Examine Manager. This script is going to be responsible of setting the cube position based on the function called.

This script will contain four variables:

  • A Serialized Field to store the examine target transform.
  • A Examinable variable to store the current examinable object.
  • A Vector 3 to store the position of the cube before we examine it.
  • A Quaternion to store the rotation of the cube before we examine it.

I’ll create two public functions to examine and to unexamine the cube.

In the examine function I’m going to:

  • Get the current examinable object.
  • Store the position and rotation of the cube before we examine it.
  • Set the cube position to the examine target position.
  • Set the examine target as the cube’s parent.

In the unexamine function I’m going to:

  • Set the cube position and rotation back to where it was before we examined the object.
  • Set the cube’s parent to none.

Let’s call these functions in the examinable script.

Now I can call these functions in the Cube’s AR Selection Interactable Select event. I want to call the Request Examine when the object is selected and call the Request Unexamine when the object is unselected.

Now I can get a closer look at the cube when I select it.

--

--