- Home /
Raycasting an object in oculus
I am trying to design a game for the oculus rift that is moving an object on a plane using the mouse. I have a code that works great in unity but when I load the game into the oculus, both the camera and mouse move the object. Does anyone know if there is a way to separate the head movement from the mouse movement (maybe casting from a child of the object I am trying to move)? Thank you!
Here is the code that I have so far...
RaycastHit hit;
private float raycastLength = 1000;
void Update()
{
GameObject Mouse = GameObject.Find ("Mouse");
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
if (Physics.Raycast (ray, out hit, raycastLength)) {
Debug.Log (hit.collider.name);
if (hit.collider.name == "Tablet")
{
Mouse.transform.position = hit.point;
}
}
Debug.DrawRay(ray.origin, ray.direction * raycastLength, Color.yellow);
}
}
Answer by KdRWaylander · Aug 07, 2015 at 09:20 AM
On what object(s) is this script on ?
Camera.main calls the first camera tagged Main Camera that Unity finds, you should be more specific when you choose from where to launch your ray. Like shoot only from the left eye or so.
Your answer
Follow this Question
Related Questions
Raycasting with Oculus and Leap Motion 0 Answers
oculus, gui and menu not showed correctly 0 Answers
How to disable automatic recentering when using OVRCameraRig 0 Answers
Oculus rendeing bug 0 Answers
the coordinates of maincamera are changed wrongly. 0 Answers