- Home /
(Raycasting) Changing Position
So I am currently working with an oculus rift and im trying to raycast depending on where the player is looking with the vr headset. Currently it seems like it's only raycasting directly out in one direction, when I need it to do all directions and follow where the player is looking. Here's what I have so far, how would I change it so it would track where a user is looking around?
if(Physics.Raycast(transform.position,transform.forward,hit,100)){
print ("There is something in front of you!");
if(hit.collider.gameObject.tag == "found"){
foundObject = hit.collider.gameObject;
Destroy(foundObject);
//x++;
//print(x);
}
}
Try replace
if(Physics.Raycast(transform.position,transform.forward,hit,100)){
to
if(Physics.Raycast(transform.position,transform.TransformDirection(Vector3.forward),hit,100)){
I don't see where you code is looking at / getting the input device data. Whether a mouse, keyboard or VR headset, you need to get the data supplied by the input device, somehow. That being said, I'm not sure how to do it with oculus rift, but I did find this answer which offers a solution I cannot test out: http://answers.unity3d.com/questions/714931/oculus-device-input-required.html
Your answer
Follow this Question
Related Questions
Raycasting problems 1 Answer
Placing object where ray collides 1 Answer
cast a ray to hit an object in the center of the screen 1 Answer
Raycast object as far as possible? 1 Answer
Raycast script help? 1 Answer