I am currently using unity with a Oculus rift running a OVRCameraRig and a script attached to the CenterEyeAnchor on it. This script uses the following code.
GameObject dot;
void Start () {
dot = GameObject.CreatePrimitive(PrimitiveType.Sphere);
dot.GetComponent<Renderer>().material.color = Color.red;
dot.layer = 2;
dot.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
}
void Update () {
RaycastHit hit;
if (Physics.Raycast(transform.position, Vector3.forward, out hit, 80.0f))
{
dot.transform.position = hit.point;
}
else
{
dot.transform.position = transform.forward * 80 + transform.position;
}
}
When I run the following code without a rift headset plugged in, the RayCast collides with all objects (whilst moving the OVRCameraRig within the scene) however if i restart the program with my rift plugged in, the raycast goes through all objects and hence moves the ball 80 units away from you. I am wondering why the RayCasts behaviour would change after i plug in the headset and if there would be a way to stop this.
Edit: While debugging the following code it seems that when the rift is connected the raycast always fails to hit on all objects
Was a simple mistype of using Vector3.forward in the Raycast rather than transform.forward