Making an Object Stick to AR Plane during Translation in Unity

Making an Object Stick to AR Plane during Translation in Unity

When moving objects using ARFoundation in Unity, you often want them to stick to detected surfaces like planes or the floor. Here is one way to achieve this:

First, add the **ARPlaneManager** and **ARRaycastManager** to your scene. This will detect planes and handle raycasting.

On the gameobject you want to translate, create a script with the following:

Copy code

public Camera arCamera; public GameObject objectToTranslate; void Update() { if(Input.touchCount > 0) { Ray ray = arCamera.ScreenPointToRay(Input.GetTouch(0).position); if(Physics.Raycast(ray, out RaycastHit hit)) { // Move object to surface point hit objectToTranslate.transform.position = hit.point; } } }


This raycasts from the touch point to the surface. If it hits, it will move the object to that plane position.

You can expand on this by lerping movement, adding surface normal checks, and constraining only to horizontal planes.

The key point is to use the raycast hit point to stick the object to the detected surface while dragging. This allows translating an object that stays anchored to the correct AR plane or floor.


You can combine this technique with any AR object manipulation like gestures or hand tracking to enable natural interactions.