Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

Help Wanted I want to place placement pose indicator on both vertical and horizontal plane in Ar foundation

Discussion in 'AR' started by unityanandprakash, Sep 1, 2021.

  1. unityanandprakash

    unityanandprakash

    Joined:
    Jan 22, 2019
    Posts:
    2
    I want to place placement pose indicator on both vertical and horizontal plane in AR foundation

    what i am trying is working on horizontal plane only, here is code snippet...

    Please help to me to find out solution:-- Thanks

    private void UpdatePlacementIndicator()
    {
    if (placementPoseIsValid)
    {
    placementIndicator.SetActive(true);
    //TrackableId planeHit_ID = hits[0].trackableId;
    //ARPlane planeHit = arPlaneManager.GetPlane(planeHit_ID);
    //Quaternion q = Quaternion.FromToRotation(planeHit.transform.up, placementIndicator.transform.up);
    placementIndicator.transform.SetPositionAndRotation(placementPose.position, placementPose.rotation);
    // placementIndicator.transform.rotation = q * transform.rotation;
    }
    else
    {
    placementIndicator.SetActive(false);
    }
    }
    Pose pos;
    List<ARRaycastHit> hits;
    private void UpdatePlacementPose()
    {
    var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f, 0.5f));

    hits = new List<ARRaycastHit>();


    raycastManager.Raycast(screenCenter, hits, TrackableType.All);

    placementPoseIsValid = hits.Count > 0;

    if (placementPoseIsValid)
    {

    placementPose = hits[0].pose;

    var cameraForward = Camera.current.transform.forward;

    var cameraBearing = new Vector3(cameraForward.x,0, cameraForward.z).normalized;

    placementPose.rotation = Quaternion.LookRotation(cameraBearing);

    }
    }
     
unityunity