How to place an object in a fixed position in the air?

So far have used target and planes to place my AR objects. I have seen demos where a user was able to place an object in a fixed position as though it were floating in the air.

How is this accomplished and is there any demo I can reference?

you could instantiate the object e.g. 3 meters in front of the camera.

To make sure the object stays on that position, if you dont want to be raycasting directly to a ground plane, raycast down to a ground plane from a point in front of the camera and in the air that is 3 meters in front of the camera and instantiate then.

Hope that makes sense.

Cheers

Thanks. Would you know if there is a demo in the ARKit Unity package that I could reference as a starting point?

Sorry I don't. In ARFoundation this raycast overload can help you:

public bool Raycast(Ray ray, List hitResults, TrackableType trackableTypeMask = TrackableType.All, float pointCloudRaycastAngleInDegrees = 5f);

You can set the ray pointing down from an object e.g.3m in front of the camera.

@Tarrag ... why we need a raycast to the ground plane???? doesnt it stay 3m in front of the camera always if we simply instantiate it in 3m forward ??

I get more control of the obj's position if stuck to a plane

so you suggesting cast a ray from 3m in front of the camera to the ground plane and if it is hitting on a trackable plane change the obj's position in accordance to the hit position
??

Raycast 3m in front of cam then down to hit the plane yup. Along these lines:

Ray ray = new Ray(obj.transform.position, Vector3.down);
if(m_ArRaycastManagerScript.Raycast(ray, s_Hits, TrackableType.PlaneWithinPolygon))

where obj is 3m in front of cam

@Tarrag thanks for your helping replays .... what we need to do after the ray hit on the plane .... do we need to add some reference point in the hit position and make obj's as child or this reference point?????
if then .can u give an example of adding reference point

it's cool :)
you can instantiate/move the obj once you raycast to a plane, that's enough to track. But yes, tracking should improve with a ref point but that's not something I've yet managed to implement or could get an answer https://forum.unity.com/threads/unity-freezes-when-tryremovereferencepoint-ar-foundation.686329/

1 Like

okay.. thanks bro... am also figuring out to implement reference point:)