Search Unity

HTC Vive -Fly/Walk with vive controllers free from vr sickness???

Discussion in 'AR/VR (XR) Discussion' started by Harald_Heide, Aug 9, 2016.

  1. Harald_Heide

    Harald_Heide

    Joined:
    Jul 22, 2015
    Posts:
    81
    /*
    * Import steam VR asset from Asset Store
    * Place the [CameraRig] Prefab in your scene.
    * Add Component Rigidbody to [CameraRig]
    * Turn off Use Gravity and turn on
    * Constraints... Freeze Rotation... X, Y and Z.
    *
    * Add Box Collider to Camera (Eye)
    * Center: 0,-0.7,0
    * Size: 0.3, 1.8, 0.3
    *
    * Add this script to a Controller (left) or (right)
    * Drive Force: 8 and Gravity: -5 should be nice for walking
    *
    * Gravity:0 gives you the power of flying.
    *
    * Press the TouchPad on your Controller and off you go...
    *
    */

    using UnityEngine;
    using System.Collections;

    [RequireComponent(typeof(SteamVR_TrackedObject))]
    public class CR_Walk_VR : MonoBehaviour
    {
    [SerializeField]
    float DriveForce = 8.0f;
    [SerializeField]
    float Gravity = -5.0f;


    Rigidbody _rigidbody;
    SteamVR_TrackedObject _trackedObject;
    Vector3 _forwardForce;
    bool _go = false;
    SteamVR_Controller.Device device;
    void Awake()
    {
    _trackedObject = GetComponent<SteamVR_TrackedObject>();
    _rigidbody = this.transform.GetComponentInParent<Rigidbody>();
    if (Gravity > 0)
    { Gravity = 0; }
    }
    void Start()
    {
    device = SteamVR_Controller.Input((int)_trackedObject.index);
    }
    void Update()
    {
    if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
    {
    _go = true;
    }
    else
    {
    _go = false;
    }
    }
    void FixedUpdate()
    {
    if (Gravity <= 0)
    {
    _rigidbody.AddForce(new Vector3(0f, Gravity, 0f));
    }
    // add force
    if (_go)
    {
    _forwardForce = Vector3.forward;
    _rigidbody.AddForce(transform.rotation * _forwardForce * DriveForce);
    _rigidbody.maxAngularVelocity = 2f;
    }
    }
    }
     
    Last edited: Aug 9, 2016
  2. Harald_Heide

    Harald_Heide

    Joined:
    Jul 22, 2015
    Posts:
    81
    Would be nice if someone could try this approach to moving around with HTC Vive controllers and post if they experience dizziness or naseua or whateva...

    Afterwards try without freezing rotation X Y Z on Rigidbody and try bumping into stuff, but then don't blame me if you experience dizziness or naseua or whateva... :)