Search Unity

Getting pointer position

Discussion in 'EditorXR' started by KushMathur, Oct 22, 2019.

  1. KushMathur

    KushMathur

    Joined:
    Jul 3, 2019
    Posts:
    22
    Hey guys!

    So in my project, I would like to have the exact vector3 points of the position where my pointer is intersecting with the first gameobject.

    So far, I was thinking to use GetPointerPosition(rayOrigin), from the interface IUsesPointer, as it is supposed to return the position of the pointer for a given ray origin. But somehow, rayOrigin.position and GetPointerPosition(rayOrigin) is getting me the same output even when I have tried is from multiple location within the game.

    Is their any other way to get the pointer position?
     
  2. amirebrahimi_unity

    amirebrahimi_unity

    Joined:
    Aug 12, 2015
    Posts:
    400
  3. KushMathur

    KushMathur

    Joined:
    Jul 3, 2019
    Posts:
    22
    Hi @amirebrahimi_unity ,
    Thank you for your quick reply!

    I did tried it out but GetFirstGameObject()
    would be good if I would like to select the gameobject through which my pointer intersects? In my case I wish to get the vector3 coordinates of the point where my pointer intersects any of the gameobjects. I tried to use this code
    Code (CSharp):
    1. var pointerPosition = this.GetPointerPosition(rayOrigin);
    2.  
    3.                         Selector = new Ray(pointerPosition, rayOrigin.forward);
    4.  
    5.                         RaycastHit hit;
    6.  
    7.                         if (Physics.Raycast(Selector, out hit))
    8.  
    9.                         {
    10.  
    11.                             Holes[3] = hit.point;
    12.  
    13.                         }
    And it is working so far. Would their be a better way out?

    Thanks!
     
  4. amirebrahimi_unity

    amirebrahimi_unity

    Joined:
    Aug 12, 2015
    Posts:
    400
    Nope. Looks good to me.