Gravity Compensated Acceleration Vector
Here's the code to get a gravity compensated acceleration vector from the Oculus Sensor:
Drag the RightCamera object in the Rift Camera Prefab to the "RiftCam" slot. It needs this to use the orientation of the Rift to compensate for gravity. Not the best way, but InversePointTransform only takes transforms, so the RightCam already has one pre-made.
Enjoy.
using UnityEngine;
using System.Collections;
public class Derp : MonoBehaviour {
public GameObject RiftCam;
float x = 0 ;
float y = 0;
float z = 0;
// Update is called once per frame
void Update () {
OVRDevice.GetAcceleration(0, ref x, ref y, ref z);
Vector3 Down = new Vector3(RiftCam.transform.position.x, RiftCam.transform.position.y+9.81f, RiftCam.transform.position.z);
Down = RiftCam.transform.InverseTransformPoint(Down);
Vector3 GravityCompensatedAcceleration = new Vector3(x-Down.x,y-Down.y,z+Down.z);
}
}
Drag the RightCamera object in the Rift Camera Prefab to the "RiftCam" slot. It needs this to use the orientation of the Rift to compensate for gravity. Not the best way, but InversePointTransform only takes transforms, so the RightCam already has one pre-made.
Enjoy.
