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);
        }
    }
}

Hardware: ASUS X99A Motherboard

Motherboard: $229 ($30 rebate) [ASUS X99-A] [amazon] [newegg]

Memory: $119 CORSAIR Vengeance LPX 16GB (2 x 8GB) 288-Pin DDR4 2666 [amazon] [newegg]

Processor: $399 Intel Core i7-6800K Processor (3.60 GHz) [amazon] [newegg]

CPU Cooler: $41.99 [Cooler Master GeminII S524 Version 2 CPU Air Cooler with 5 Direct Contact Heat Pipes]

Power Supply: $144.99 [Corsair RMi Series, RM850i, 850 Watt (850W)]

Power Supply: $130.27 EVGA SuperNOVA 850W G3 [amazon] [newegg]

Case: $89.97 [DIYPC Skyline-07-R Black/Red SPCC ATX Full Tower]

Wireless Networking: $112.99 [ASUS 4×4 802.11AC Wireless-AC3100 PCIe] [amazon] [driver]

Harddrive: $259.99 WD Blue 1TB Internal SSD Solid State Drive [amazon] [newegg]

Graphics: $579.99 [ASUS GeForce GTX 1080 8GB ROG STRIX]

[Processors]

[Memory]

[CPU Cooler]

[win10]

Belarc Advisor

MS Support was driving my PC trying to activate Windows 10 when I saw them install [Belarc Advisor] in order to fetch the installed product keys installed on my machine. In the end it didn’t work and I had to enter the product key from Windows 7 to activate Windows 10. It just interesting that they used 3rd party software. Even more odd was that all the support tools where not on a microsoft subdomain, which looks highly suspect. A.k.a `secure.logmeinrescue-enterprise.com`