SteamVR: Unity Move/Rotate With Motion Controller Sticks

The [SteamVR] API makes the motion controller touchpad input available.

1 Import the SteamVR Plugin

2 Open the `Assets\SteamVR\InteractionSystem\Samples\Scenes\Interactions_Example.unity` scene

3 Attach `StickManipulation.cs` on the SteamVR `Player`.

using UnityEngine;
using Valve.VR;
using Valve.VR.InteractionSystem;

public class StickManipulation : MonoBehaviour
{
    private float _mMoveSpeed = 2.5f;
    private float _mHorizontalTurnSpeed = 180f;
    private float _mVerticalTurnSpeed = 2.5f;
    private bool _mInverted = false;
    private const float VERTICAL_LIMIT = 60f;

    private void OnGUI()
    {
        Player player = Player.instance;
        if (!player)
        {
            return;
        }

        EVRButtonId touchPad = EVRButtonId.k_EButton_SteamVR_Touchpad;

        if (null != player.leftController)
        {
            var touchPadVector = player.leftController.GetAxis(touchPad);
            GUILayout.Label(string.Format("Left X: {0:F2}, {1:F2}", touchPadVector.x, touchPadVector.y));
        }

        if (null != player.rightController)
        {
            var touchPadVector = player.rightController.GetAxis(touchPad);
            GUILayout.Label(string.Format("Right X: {0:F2}, {1:F2}", touchPadVector.x, touchPadVector.y));
        }
    }

    float GetAngle(float input)
    {
        if (input < 0f)
        {
            return -Mathf.LerpAngle(0, VERTICAL_LIMIT, -input);
        }
        else if (input > 0f)
        {
            return Mathf.LerpAngle(0, VERTICAL_LIMIT, input);
        }
        return 0f;
    }

    // Update is called once per frame
    void Update()
    {
        Player player = Player.instance;
        if (!player)
        {
            return;
        }

        EVRButtonId touchPad = EVRButtonId.k_EButton_SteamVR_Touchpad;

        if (null != player.leftController)
        {
            Quaternion orientation = Camera.main.transform.rotation;
            var touchPadVector = player.leftController.GetAxis(touchPad);
            Vector3 moveDirection = orientation * Vector3.forward * touchPadVector.y + orientation * Vector3.right * touchPadVector.x;
            Vector3 pos = player.transform.position;
            pos.x += moveDirection.x * _mMoveSpeed * Time.deltaTime;
            pos.z += moveDirection.z * _mMoveSpeed * Time.deltaTime;
            player.transform.position = pos;
        }

        if (null != player.rightController)
        {
            Quaternion orientation = player.transform.rotation;
            var touchPadVector = player.rightController.GetAxis(touchPad);

            Vector3 euler = transform.rotation.eulerAngles;
            float angle;
            if (_mInverted)
            {
                angle = GetAngle(touchPadVector.y);
            }
            else
            {
                angle = GetAngle(-touchPadVector.y);
            }
            euler.x = Mathf.LerpAngle(euler.x, angle, _mVerticalTurnSpeed * Time.deltaTime);
            euler.y += touchPadVector.x * _mHorizontalTurnSpeed * Time.deltaTime;
            player.transform.rotation = Quaternion.Euler(euler);
        }
    }
}

Unity: SteamVR Center View

The Unity [SteamVR Plugin] has an API to center the VR view. It’s great when VR apps have a key mapped to do this.

using UnityEngine;
using Valve.VR;

public class SteamVRRecenter : MonoBehaviour
{
    // Keep the script around
    private void Start()
    {
        DontDestroyOnLoad(gameObject);
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKeyUp(KeyCode.L))
        {
            var system = OpenVR.System;
            if (system != null)
            {
                system.ResetSeatedZeroPose();
            }
        }
    }
}

Steam: SteamVR Plugin for Razer Hydra

[SteamVR Plugin for Razer Hydra]

** Caution: Be sure to close any Game, UE4, Unreal Launcher, SteamVR, and Unity processes that are running before installing.

Source: [steamvr_driver_hydra]

Install "SteamVR" - steam://install/250820

Install "Sixense SDK for the Razer Hydra" - steam://install/42300

Install "SteamVR Driver for Razer Hydra" - steam://install/491380

[issue]

OSVR: Setup SteamVR

SteamVR has support for OSVR. I tested with an OSVR HDK2.

Install SteamVR:

steam://install/250820

I used the OSVR control panel to flash the HDK2 to the [latest firmware] (`hdk2svr-2.00.hex`).

The setup instructions can be found at the [SteamVR-OSVR] project.

[Kevin Godby] is the developer of the SteamVR-OSVR plugin.

[Russell Taylor] is the primary RenderManager developer.

The 7zip archive with the pre-built Windows drivers can be found in the [files] section.

Extract the archive.

Copy the `SteamVR-OSVR\lib\openvr\osvr` folder to `C:\Program Files (x86)\Steam\steamapps\common\SteamVR\drivers` folder as a subfolder.

Initially, the SteamVR tutorial was up-side down. I found a solution on Reddit. [New SteamVR-OSVR driver available: fixes display orientation]

Close `SteamVR` and `Steam` before editing the `C:\Program Files (x86)\Steam\config\steamvr.vrsettings` file.

{
   "driver_osvr" : {
      "scanoutOrigin" : "lower-right",
      "verbose" : true
   },
   "steamvr" : {
      "mirrorViewGeometry" : "0 0 1080 600"
   }
}

Be sure to relaunch the OSVR server before starting SteamVR.

Relaunch Steam, and the SteamVR tutorial.

Issues:

[Main monitor on different GPU prevents VR applications detecting Vive]

Since I have dual graphics cards, I had to swap graphics cards slots to get SteamVR to recognize the headset in Direct Mode.

There’s a couple important logs for debugging `SteamVR` issues.

* `C:\Program Files (x86)\Steam\logs\vrcompositor.txt`

* `C:\Program Files (x86)\Steam\logs\vrserver.txt`