Created
November 29, 2014 23:34
-
-
Save takashiski/930bdde80039719a4955 to your computer and use it in GitHub Desktop.
Oculus riftの上下に揺れて進むあれ
This file contains 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; | |
using Ovr; | |
public class VelocityChecker : MonoBehaviour { | |
Hmd hmd; | |
float prevVelY; | |
// Use this for initialization | |
void Start () { | |
hmd = OVRManager.capiHmd; | |
prevVelY = 0; | |
} | |
// Update is called once per frame | |
void Update () { | |
Vector3 velocity3 = GetVelocity(); | |
float velY = velocity3.y - 9.8f; | |
if (Mathf.Abs(velY) > 5)//f && 2f > Mathf.Abs(velY+prevVelY)) | |
{ | |
transform.Translate(transform.forward * Mathf.Abs(velY) * Time.deltaTime); | |
} | |
prevVelY = velY; | |
} | |
Vector3 GetVelocity() | |
{ | |
TrackingState trackingState = hmd.GetTrackingState(); | |
SensorData sensorData = trackingState.RawSensorData; | |
return new Vector3(sensorData.Accelerometer.x,sensorData.Accelerometer.y,sensorData.Accelerometer.z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment