Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

AR Foundation placement indicator tracking issue

Discussion in 'AR' started by Vallar, Nov 30, 2019.

  1. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hi all,

    So I am working on AR experience using the latest AR Foundation version and for some reason suddenly the tracking on the placement indicator (experience we track planes, show an indicator of some model being placed and then when user taps, the model is placed) stopped following correct positions and rotations.

    First my code:

    Code (CSharp):
    1. public void DisplayPlacementPointer()
    2.     {
    3.         raycastManager.Raycast(new Vector2(Screen.width / 2f, Screen.height / 2f), hits, TrackableType.Planes);
    4.  
    5.         if (hits.Count > 0)
    6.         {
    7.             if (currentPointer == null)
    8.                 currentPointer = Pooling.GetObject(pointerPrefab);
    9.  
    10.             planeFound.RaiseEvent();
    11.  
    12.             //currentPointer.position = hits[0].pose.position;
    13.             //currentPointer.rotation = hits[0].pose.rotation;
    14.  
    15.             currentPointer.SetPositionAndRotation(hits[0].pose.position, hits[0].pose.rotation);
    16.         }
    17.         else
    18.             ResetPointer();
    19.     }
    This is running in Update of course. Now the problem is that the position of the currentPointer (placement indicator in this case) is always reversed. If I move the phone upwards (i.e. looking towards the sky), the currentPointer moves downwards. If I move the phone downwards (i.e. look towards the floor), the currentPointer object moves upwards.

    This is done indoors with a good lighting in the room (tried outdoors too despite the experience is setup for indoors).

    I tried removing ARFoundation and adding it back again, same issue. Pretty sure there are planes detected (AR Plane Manger drew them as well as the AR Cloud).

    Any ideas what is wrong here?
     
  2. AjBaruah

    AjBaruah

    Joined:
    Mar 14, 2019
    Posts:
    8
    Hey vallar, I am pretty new to ArFoundation myself but this is what i did for my project
    Code (CSharp):
    1.  var cameraForward = Camera.current.transform.forward;
    2.  var cameraBearing = new Vector3(cameraForward.x, 0, cameraForward.z).normalized;
    3.  hits[0].pose.rotation = Quaternion.LookRotation(cameraBearing);
    Hope this helps :)