Can’t see to get RayCasting to work from the Rift. I have created a cube and added the following script using the OVR CenterEyeAnchor as CameraFacing GameObject. The cube appears to track perfectly to my head movments but its RayCast seems to be off by at least 15 degrees.
using UnityEngine;
using System.Collections;
public class Gaze2 : MonoBehaviour {
public GameObject CameraFacing;
public float Distance=10;
public float SphereSize=0.2f;
public GameObject HitName;
public GameObject TheHitName;
// Use this for initialization
void Start () {
Distance = 10;
TheHitName = null;
}
// Update is called once per frame
void Update () {
transform.LookAt(CameraFacing.transform.position);
transform.Rotate (0.0f, 180.0f, 0.0f);
transform.position=CameraFacing.transform.position + CameraFacing.transform.rotation*Vector3.forward * .3f;
CastSphere ();
}
public void CastSphere()
{
RaycastHit hit;
Vector3 p1 = transform.position;
var fwd = transform.TransformDirection (Vector3.forward);
if (Physics.SphereCast (p1, SphereSize, fwd, out hit, Distance)) {
HitName = hit.collider.gameObject;
print (HitName.name);
//return HitName;
TheHitName=HitName;
}
//return null;
TheHitName = null;
}
}