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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Position of an active MRTK 3 pointer

Discussion in 'XR Interaction Toolkit and Input' started by camroo29, Jun 24, 2023.

  1. camroo29

    camroo29

    Joined:
    Feb 7, 2020
    Posts:
    7
    Hi,

    I have started to port my application from MRTK 2 to MRTK 3. Since MRTK 3 architecture has been redesigned based on XRI, porting MRTK 2 application is a little confusing especially how to get the coordinates of an active Pointer or controller. Previously for MRTK 2, I could use the following:


    Code (CSharp):
    1.  
    2.         foreach(var source in MixedRealityToolkit.InputSystem.DetectedInputSources)
    3.         {
    4.             if (source.SourceType == Microsoft.MixedReality.Toolkit.Input.InputSourceType.Hand)
    5.             {
    6.                 foreach (var p in source.Pointers)
    7.                 {
    8.                     if (p is IMixedRealityNearPointer)
    9.                     {
    10.                          continue;
    11.                     }
    12.                     if (p.Result != null)
    13.                     {
    14.                         var startPoint = p.Position;
    15.                         var endPoint = p.Result.Details.Point;
    16.                         var hitObject = p.Result.Details.Object;
    17.                     }
    18.                 }
    19.             }
    20.         }
    21.    
    For MRTK 3, I couldn't find Input sources directly. Also, MRTK 3 API doesn't provide examples of extracting pointer coordinates.

    I have used Solver to achieve that but it's not really accurate. If anyone has any idea that would be really helpful.

    Thanks
     
  2. Jom000

    Jom000

    Joined:
    Aug 21, 2015
    Posts:
    8

    I'm having the same problem, the documentation for MRTK3 is very incomplete.
    Can you please share the method to get the location using Solver?
     
  3. camroo29

    camroo29

    Joined:
    Feb 7, 2020
    Posts:
    7
    Keep a reference of your Left/Right hand Fay Ray in your script (e.g. _leftHand for me). Then based on the type of interactor, you can do raycasting:
    Code (CSharp):
    1. (_leftHand.TryGetCurrentUIRaycastResult(out _result))
    _result.worldPosition is your pointer hit position.