Search Unity

Rotating a prefab for Vertical Planes

Discussion in 'AR' started by JohnnyBig, Nov 17, 2019.

  1. JohnnyBig

    JohnnyBig

    Joined:
    Oct 16, 2019
    Posts:
    3
    Hi , I've tried every possible combination of rotating my indicator based on the alignment of the plane but can not seem to get it vertical even in the slightest.

    Code (CSharp):
    1.            AnchorIndicator.SetActive(true);
    2.             var pose = planeHits[0].pose;
    3.  
    4.             var alignment = arSessionOrigin.GetComponent<ARPlaneManager>().GetPlane(planeHits[0].trackableId).alignment;
    5.             Debug.Log("Alignment = " + alignment);
    6.  
    7.             var xRotaion = alignment == UnityEngine.XR.ARSubsystems.PlaneAlignment.Vertical ? -90 : 0;
    8.            
    9.             var cameraForward = Camera.main.transform.forward;
    10.             var cameraBearing = new Vector3(cameraForward.x  + xRotaion , 0, cameraForward.z ).normalized;
    11.  
    12.             pose.rotation = Quaternion.LookRotation(cameraBearing);
    13.          
    14.             AnchorIndicator.transform.SetPositionAndRotation(pose.position, pose.rotation);
    15.         }
    Any tips in the right direction would be greatly appreciated.