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

Question RayInteractor + SimpleInteractable - detect Grip VS Trigger button

Discussion in 'XR Interaction Toolkit and Input' started by OlaBrahammar, Feb 21, 2022.

  1. OlaBrahammar

    OlaBrahammar

    Joined:
    Jan 9, 2017
    Posts:
    10
    Short version:
    How can a XRSimpleInteractable - pointed at by a XRRayInteractor, react differently to a trigger-button press compared to a 'grip'-button press from the ray-hand?

    Longer version:
    Holding a "3D Minimap" with my lefthand controller, i 'ray-point' into the map with my right hand. Now, i want to perform different functions depending on which controller buttons is pressed while pointing into the minimap.

    Currently i add a listener to the Minimaps XRSimpleInteractable.SelectEntered, which captures "gun-trigger" presses just fine, but it does not react at all to "grip"-button presses. How can i detect which button was pressed while pointing at the SimpleInteractable object?

    This must be trivial, what am i missing? ;-)
     
  2. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    254
    Hey @OlaBrahammar,
    A couple of questions for you. What is the intended purpose of the Grip button press when pointing at the map? Are you trying to switch hands the map is held in or are you trying to use it as more of a 'right-click' context menu? How many buttons are you trying to support for the map? Also are you using the Action-Based or Device-Based XR Controller component?
     
  3. OlaBrahammar

    OlaBrahammar

    Joined:
    Jan 9, 2017
    Posts:
    10
    Hi @VRDave_Unity - the intended purpose of the right-hand grip button, in this case, is that it initiates 'dragging' a horizontal "clip-plane" at the ray-hitpoint in the minimap. (The map model has ~12 floors and is actually a real oil rig in the North Sea. Huge!), so this clip-plane i can raise/lower to cutaway obscuring floors to see what is deeper down in the structure). So, it is in a way a context-dependent action. I use the Action-Based XR Controller.
    For now, i have solved my issue by polling SimpleInteractable.isHovered in Update() and checking what action WasPressedThisFrame like see:
    upload_2022-3-1_23-19-41.png
    This works just fine and might even be the best solution because of how flexible it is, but polling stuff in Update() irritates my OCD and i sense there might be an intended 'pattern' for solving this scenario in XRITK, that i have not understood.

    A hint at what i have not understood could be the fact that i have to "manually", temporarily, disable other actions that have the same "key bindings", while i have the minimap open. (The map works pretty much exactly the same way as Google Earth VR's hand-held globe, where you can ray-point and place a pin to teleport, except i have more actions than just teleport that are location-dependent)