Search code examples
controllerhololensmotioncollider

Is there a GazeManager.Instance.HitInfo.collider but for motioncontroller pointer ray on opaque WMR headsets instead of the same on HoloLens?


I would like to know if a built-in Mixed Reality ToolKit way to check whether ray projected from a motion controller visualized by MRTK-Unity when using the controllers with an occluded windows mixed reality headset is raycasting anything exists?

I can check this easily on HoloLens when using a GazeManager.Instance.HitInfo.collider != null condition, but since that Gaze Manager pertains to Gaze instead of MotionControllers I can't use that (at least in a way I know) to check if the defaultcursor which is controlled by the motioncontroller projected ray is being projected/raycsted onto something UI or not (and possibly later what)?

P.S. I saw that MRTK-Unity v2 plans to combine all the pointers (gaze and controllers/hands) in input manager class, but unless I'm wrong that's not available for HoloLens v1, I mean being able to get the pointer for controller since I looked at the InputManager prefab for v1 and couldn't find anything like that...right?


Solution

  • Simple raycasting could be implemented using Physics.Raycast() with parameters from a motion controller. The parameters can be taken from MRTK Input. As an example

    void InteractionManager_InteractionSourcePressed(InteractionSourcePressedEventArgs args)
    {
         var interactionSourceState = args.state;
         var sourcePose = interactionSourceState.sourcePose;
         Vector3 sourceGripPosition;
         Quaternion sourceGripRotation;
         if ((sourcePose.TryGetPosition(out sourceGripPosition, InteractionSourceNode.Pointer)) &&
             (sourcePose.TryGetRotation(out sourceGripRotation, InteractionSourceNode.Pointer))) {
             RaycastHit raycastHit;
             if (Physics.Raycast(sourceGripPosition, sourceGripRotation * Vector3.forward, out raycastHit, 10)) {
                 var targetObject = raycastHit.collider.gameObject;
                 // ...
             }
         }
    }