Perform a hit test against detected planes
In the previous step, you programmed an application that can detect planes. These planes are reflected in your game's scene. Now, you'll add interactivity with these planes by creating an aiming reticle and a car that will drive on the detected plane's surface.
The control scheme for this app involves the player pointing their phone at a surface. In order to give clear visual feedback for the designated location, you'll use an aiming reticle.
![](https://xreal.gitbook.io/~gitbook/image?url=https%3A%2F%2F1363773068-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FL6MonFe6Phoj4t5Xi1d0%252Fuploads%252FAm2ouNqk1eebqBVo8Cis%252Fimage.png%3Falt%3Dmedia%26token%3D93b4278f-065b-4766-ba58-2e647d0bf295&width=768&dpr=4&quality=100&sign=49d6cf34&sv=1)
In order to "stick" this reticle to an AR plane, use a hit test. A hit test is a technique that calculates intersections when casting a ray in a given direction. You will use a hit test to detect an intersection in the direction of your controller.
Create ReticleBehaviour
script
ReticleBehaviour
script1.In Assets/Script
folder, right click -> Create -> C# Script, name the C# script ReticleBehaviour
![](https://xreal.gitbook.io/~gitbook/image?url=https%3A%2F%2F1363773068-files.gitbook.io%2F%7E%2Ffiles%2Fv0%2Fb%2Fgitbook-x-prod.appspot.com%2Fo%2Fspaces%252FL6MonFe6Phoj4t5Xi1d0%252Fuploads%252FazqPQiUWywbr5VBJNYav%252Fimage.png%3Falt%3Dmedia%26token%3Dbebc9552-d222-4f8a-bece-99298366c0cc&width=768&dpr=4&quality=100&sign=fd42c3e4&sv=1)
Edit ReticleBehaviour
as following:
The ReticleBehavior
script will position the reticle on the plane that hits against the controller raycast.
Create the Reticle
In the Project pane near the bottom of the screen, navigate to Assets > PlaneDetectionStarterPackage.
Place the Reticle Prefab into the scene by dragging it into the project's Hierarchy pane.
Select the reticle in the hierarchy.
In the inspector, click Add Component. Add the
ReticleBehaviour
script you've created.
Test the reticle
Click File > Build to build and test your changes asyou did before.
You should see the reticle follow your controller's raycast movements.
Last updated