2
\$\begingroup\$

Right. So basically I want to map the Vive motion controller touchpads (certain locations) to the certain inputs in Unity's InputManager. How do I do this? Like I want a certain area on the touchpad to equate to forwards/backwards in the InputManager. How would I do this? I am not seeing a way to do it natively.

Long story short I'm wondering if I can use the Vive with the InputManager or not.

\$\endgroup\$
1
\$\begingroup\$

Unity's InputManager isn't well suited for this task, I strongly recommend interfacing directly with the APIs that SteamVR provides for Unity games:

SteamVR_Controller.Device.GetAxis is most likely going to be the easiest way to get the behavior you want:

public Vector2 GetAxis(EVRButtonId buttonId = EVRButtonId.k_EButton_SteamVR_Touchpad)

So to treat it like a joystick (for the most part):

// I assume you have a SteamVR_Controller.Device named `device` available:

// Is the touchpad being touched?
if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
{
    // This will fetch the Axis of the Touchpad by default.
    Vector2 touchpadPosition = device.GetAxis();

    // this is nearly identical to the behavior of Gamepads
    // treat touchpadPosition like the vector form of:
    // float x = Input.GetAxisRaw("Horizontal");
    // float y = Input.GetAxisRaw("Vertical");
}

I used GetAxisRaw instead of GetAxis as an example because SteamVR will handle smoothing and ranges slightly differently than the Unity default inputs, but you should be able to work around it and decide how you want to handle smoothing and dead-zones yourself.

\$\endgroup\$
0
\$\begingroup\$

I've been doing this with Oculus Touch controllers and it's been working fine. I setup the Input Manager using the scripting documentation. For Vive that's at https://docs.unity3d.com/Manual/OpenVRControllers.html .

  1. Make sure you have "Virtual Reality Supported" checked in Edit => Project Settings => Player
  2. Add a new element to Edit => Project Settings => Input. ie change 18 to 19. Change InputManager element count
  3. Setup the new input element to map to the controller. InputManager of VrRightHorizontal Name: VrRightHorizontal Gravity: 0 Dead: 0.1 Sensitivity: 1 Snap: false Invert: false Type: Joystick Axis Axis: 4th axis (Joysticks) Joy Num: Get Motion from all Joysticks

  4. Reference the axis by name in your code Debug.Log("VrRightHorizontal" + Input.GetAxis("VrRightHorizontal"));

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.