Skip to content

Instantly share code, notes, and snippets.

@takashiski
Created November 29, 2014 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takashiski/930bdde80039719a4955 to your computer and use it in GitHub Desktop.
Save takashiski/930bdde80039719a4955 to your computer and use it in GitHub Desktop.
Oculus riftの上下に揺れて進むあれ
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