Search Unity

Draw a Line(Wall) using ARKIT & Unity

Discussion in 'AR' started by spinteractive, Nov 10, 2017.

  1. spinteractive

    spinteractive

    Joined:
    Dec 19, 2015
    Posts:
    75
    I am struggling to draw a line (really I need a wall) with ARKit in Unity.

    I am using the line renderer and casting a ray. On first touch I place the line renderer (that works fine.) On second touch I attempt to place the first point (0) of the line renderer using the hit.point info (this does not work). The translation between the hit.point and the required line renderer point info does not work. I am debugging with ARKitRemote using getMouse.

    Any ideas??

    Code (CSharp):
    1. #if UNITY_EDITOR   //we will only use this script on the editor side, though there is nothing that would prevent it from working on device
    2.         void Update () {
    3.             if (Input.GetMouseButtonDown (0)) {
    4.                 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    5.                 RaycastHit hit;
    6.  
    7.                 if (Physics.Raycast (ray, out hit)) {
    8.                 //if (Physics.Raycast (ray, out hit, maxRayDistance, collisionLayerMask)) {
    9.  
    10.                     if (!firstTouch) {
    11.                         m_HitTransform.position = hit.point;
    12.                         Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", m_HitTransform.position.x, m_HitTransform.position.y, m_HitTransform.position.z));
    13.                         m_HitTransform.rotation = hit.transform.rotation;
    14.                         firstTouch = true;
    15.                  
    16.                     } else {
    17.                         Debug.Log (string.Format ("x:{0:0.######} y:{1:0.######} z:{2:0.######}", hit.point.x, hit.point.y, hit.point.z));
    18.                         Vector3 secondClick = new Vector3 (hit.point.x, 0, hit.point.z);
    19.                         lr.SetPosition (0, secondClick);
    20.                     }
    21.                  
    22.                 }
    23.             }
    24.         }
    25. #endif
     
    Last edited: Nov 10, 2017
    developersice likes this.
  2. developersice

    developersice

    Joined:
    Nov 25, 2016
    Posts:
    36
    Did you have any progress with this?