Search Unity

How to Change Grab/Interact Button on SteamVR?

Discussion in 'AR/VR (XR) Discussion' started by FGPArthurVII, Jun 7, 2018.

  1. FGPArthurVII

    FGPArthurVII

    Joined:
    Jan 5, 2015
    Posts:
    106
    Using SteamVR for Oculus Rift, The standard button for grabbing an object is the frontal (or index) trigger, but since I am grabbing a Fire Extinguisher that I wish to eventually use the index trigger to "shoot" it to put out some fire. So I'd use the lateral (Hand) button (Grip) to keep holding it, and the trigger to Spray it instead.

    I already got the line to use the button in a general use (Equivalent to Input.GetKey(KeyCode.key)):

    Code (CSharp):
    1. if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
    2. {
    3.       //action
    4. }
    5. // If of course I am placing my hand on a Throwable Object
    But analising the "Throwable", "Interactable", and ''Hand" scripts I can't seem to find where would I replace it, in order to alter the Key, at all, The line doesn't even seem to be placed anywhere on the default code. Looking on the inspector where the scripts are attached, there is no field to change it either.

    How and Where can I Change the KeyCode?

    Thanks;
    Arthur.
     
  2. CasStr

    CasStr

    Joined:
    Jan 17, 2018
    Posts:
    1
    Old thread, but deserves an answer for the next reader. The grabbing action is called in Throwable.cs in several functions. The culprit is the call
    Code (CSharp):
    1. hand.GetStandardInteractionButtonDown()
    . The standard interaction button maps to the device trigger. A quick and dirty fix could be to replace that call with
    Code (CSharp):
    1. hand.controller.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip)
    .
     
    Last edited: Oct 11, 2018
    poryjohn-z likes this.
  3. benjaminoutram

    benjaminoutram

    Joined:
    Nov 10, 2014
    Posts:
    20
    To change which buttons are used to interact in the Throwable.cs script:

    On the Hand.cs scripts attached the the LeftHand and RightHand gameobjects on the SteamVR object in the hierarchy, there are public variables designating which SteamVR action is assigned to the 'grab' (and also UI interact) functions, among other things. You can change these to be anything you like in the Inspector.

    If you want to set up a different button for grabbing, you can create a new action in the SteamVR input manager (Window>SteamVR Input) and create a new action, then hit 'Open Binding UI' and set the mapping of your action to the controller inputs.

    You can set inputs of each controller you want to support by clicking the name of the controller in the binding ui and there is a drop down to select other controller types.