Search Unity

Question Transform.position from a image tracked

Discussion in 'AR' started by bisewski, Jan 2, 2023.

  1. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    304
    Hi all.

    I am using ARTrackedImageManager in XROrigin to trace an image and and place a gameobject.

    I am not using the Tracked Image Prefab. Instead I am tracing the state and after tracked I am using a custom prefab.

    Code (CSharp):
    1.  if (trackedImage.trackingState != TrackingState.Tracking)
    After tracked I am trying to instantiate my prefab like the prefab field in ARTrackedImageManager.

    Code (CSharp):
    1.  var instance =  Instantiate(m_Prefab, trackedImage.transform.position, trackedImage.transform.rotation);
    But my prefab always is over, distance from the image. I attached an image with a red sphere and an arrow showing where the correct position.


    The curious is that if I use my phone more closer or more distance from the image the sphere position change too. Something like if I am getting the phone position not the image.

    What am I missing?

    Thank you.
     

    Attached Files:

  2. bisewski

    bisewski

    Joined:
    Jan 16, 2014
    Posts:
    304
    The problem was that I was disabling the ARtrackingImage manager after instantiate the prefab. Probably is necessary some frames to get the correct position. So I am using a button to disasble only after the completely tracking.

    Is working fine but the prefab are vibrating after disable the image track manager. I will try different size of prefab. Now I am using a 0,01 sample.
     
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    If you intend to disable image tracking after the prefab is spawned, my recommendation would be to create an anchor at the desired position and then spawn your content as a child of the anchor. At that point you should be able to disable image tracking with no issues.

    Anchors are best practice for content that should be "pinned" to a point in physical space.
     
    bisewski likes this.