Search Unity

Resolved How to pick the correct plane with ARRaycastManager

Discussion in 'AR' started by beatdesign, May 26, 2021.

  1. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    Hi,
    I always find this kind of snippet to place a "raycast indicator" on the plane I'm pointing at:
    Code (CSharp):
    1. //Raycast Planes
    2. if(arRaycastManager.Raycast(touch.position, arRaycastHits)){
    3.      var pose = arRaycastHits[0].pose;                      
    4.      PlaceRaycastIndicatorAtPos(pose.position);
    5. }
    The problem is: when I have 2 planes on different Y (let's say a table and the floor beneath it), if I point at the floor and in the camera FOV there is also the Table floor, arRaycastHits[0].pose is always the Table floor, even if I'm NOT hitting the Table Plane prefab, but I'm pointing at the Floor Plane prefab.

    I tried to use arRaycastHits[arRaycastHits.count-1].pose, but in this way I only shoftwd the problem: now the detected hitted plane is always the Floor, and not the Table (if I point to the Table).

    How to select the correct arRaycastHits index depending on what I'm pointing at?
    Thanks
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,145
    Pass the TrackableType.PlaneWithinPolygon as a third parameter to Raycast().
     
    beatdesign likes this.
  3. beatdesign

    beatdesign

    Joined:
    Apr 3, 2015
    Posts:
    137
    Exactly what I was looking for. Thank you!