Search Unity

Position AR content on x/y position on tracked image

Discussion in 'AR' started by multimediamarkers, Jul 14, 2020.

  1. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    49
    Normally I use Vuforia but i have a question: with Vuforia you can drag/drop by example a sprite on the image marker and position it exactly on the X,Y position you want. When you scan the imagetarget the sprite will be positioned exactly on the X,Y position on the recognised imagetarget.

    Is this also possible with AR Foundation Image Tracking? And how can this be accomplished in the Unity Editor?

    For customers in the past we used Vuforia to by example show video's and AR buttons on certain position on a poster and when the user scans the poster all AR elements are shown on the correct position on the poster. I like to reuse this functionality but in this case with AR foundation.

    When i now instantiate a prefab it is always in the middle of marker and i like to set the position (x,y) relative on the image target within the Unity Editor.
     
    viknesh2020 likes this.
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,144
    You can modify Tracked Image Prefab and change the position of your model. If you want different positions for different images, you can write your own Image Visualized and change model position from there.
    For example, in AR Foundation Samples you can change the position of Plane and it will add shift to all your tracked images.
    upload_2020-7-15_12-33-16.png
     
  3. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    49
    Cool ... thanks a lot . I will experiment with these position options!
     
  4. rendopan

    rendopan

    Joined:
    Jun 18, 2020
    Posts:
    1
    Hi, I have the same problem. When I start my app in front of the marker, the relative position of my game object works correctly but if I start with my device in different orientation and then move it in front of the marker I see that the game object appears in wrong position.
    If I call reset in front of the marker all works correctly but I think that it's not the better solution.
    With Unity Mars I don't see this problem.
     
  5. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    49
    I now instantiate a prefab directly under the tracked image which is a child of the Trackables GameObject. From there i can manipulate position, rotation and scale from a script on the prefab on Awake. This is working good for me.
     
  6. kislotaooankit

    kislotaooankit

    Joined:
    Apr 20, 2020
    Posts:
    15
    Hi
    can you provide some images of your environment setup and of scripts too ? like how you arranged the Game objects and set the positioning of prefabs ?
    I somewhat partially understood what we have to do it would be really helpful if someone provides some sample images while working on custom prefab and custom images
     
  7. multimediamarkers

    multimediamarkers

    Joined:
    Feb 17, 2016
    Posts:
    49
    To instantiate a prefab i use the following code:


    var markerGameObject = GameObject.Find(marker.DisplayName);
    _prefab = Instantiate<GameObject>(arContentButtonPrefab, markerGameObject.transform);

    So first find the marker and the instantiate it.

    On awake of the prefab i use code to position the instatiated prefab like:

    void Awake()
    {
    var transformButton = transform;
    transformButton.localPosition = new Vector3(positionX, 0, positionZ);
    transformButton.localScale = new Vector3(scaleX, scaleY, 0.03f);
    }