Created
July 15, 2016 21:39
-
-
Save grimmdev/64c73f58cb434408b862f459af06402f to your computer and use it in GitHub Desktop.
VR Walk Controller, Walk in place to move forward.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class WalkVRController : MonoBehaviour { | |
[SerializeField] | |
private float walkSpeed = 2f; | |
private float walkNormalize = 0.1f; | |
[SerializeField] | |
private float sensorThreshold = 1f; | |
[SerializeField] | |
private Transform targetTransform; | |
private float walkCount = 0; | |
private void Awake() { | |
Input.gyro.enabled = true; | |
} | |
private void Update () { | |
if (Shake ()) { | |
walkCount += 1; | |
LogController.i.Log ("Walked Steps:" + walkCount); | |
targetTransform.Translate (0, 0, walkNormalize * walkSpeed); | |
} | |
} | |
private bool Shake() | |
{ | |
float x = Input.gyro.userAcceleration.x; | |
float length = Mathf.Sqrt (x * x); | |
if (length >= sensorThreshold) | |
return true; | |
else | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment