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

How Can i get ARPlane Coordinate

Discussion in 'AR/VR (XR) Discussion' started by YSK1015, Jul 30, 2020.

  1. YSK1015

    YSK1015

    Joined:
    Jul 30, 2020
    Posts:
    1
    Hi. I want to draw line on AR World's Floor. So first, I use AR raycast and draw the floor. I Check the floor area is fill the Plane's Mesh. And I make a Cube that touch on plane mesh area. So I think floor's area is similar real world's floor. But I can not get the floor's Coordinate. How can i get the mesh area's Coordinate?

    Here is a Code when i make a cube when touch on mesh area and app's screenshot.

    Screenshot_20200730-213414_ARFSample.jpg


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.XR.ARFoundation;

    public class FloorEvent : MonoBehaviour
    {
    public GameObject prefabToPlace;
    public ARRaycastManager aRSessionOrigin;
    public List<ARRaycastHit> hits;

    void Start()
    {
    hits = new List<ARRaycastHit>();
    aRSessionOrigin = GetComponent<ARRaycastManager>();
    }

    void Update()
    {
    if (Input.touchCount > 0)
    {
    for (int i=0; i < Input.touchCount; i++)
    {
    Touch touch = Input.GetTouch(i);
    if (touch.phase == TouchPhase.Began)
    {
    if (aRSessionOrigin.Raycast(touch.position, hits))
    {
    Pose hitPose = hits[0].pose;
    Instantiate(prefabToPlace, hitPose.position, hitPose.rotation);
    Debug.Log("1 : "+hitPose.position);
    }
    }
    }
    }

    }
    }
     
  2. AjBaruah

    AjBaruah

    Joined:
    Mar 14, 2019
    Posts:
    8
    Hello YSK1015, I am pretty new to ARFoundation myself but I have worked on a similar project before.
    If I understand this correctly, you want the prefabToPlace to be on top of the plane created and not intersecting like it shows in the screenshot?

    If that is the case, I suggest looking at the origin of the prefabToPlace and ensure that set at the bottom. You can check this by placing it on a plane in the Editor( with transform positions set to (0,0,0)).

    Hope that helps!