0

I am trying to draw a raycast from my main camera (which is steamvr's "Camera (eye)") to my mouses point in space so I can select objects in my 3d environment. The problem is my raycast is not pointing to where my mouse is, and is probably 45+ degrees off. I will post screen shots so you can see my mouse position and the raycast position. Anyone have this problem or a solution? I am pretty positive it is a steamvrspecific problem.

Link to similar question (not answered yet)

Here is my code:

Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
Debug.DrawRay(ray.origin, ray.direction * 100, Color.red);
if (Physics.Raycast(ray, out hit))
{
   Debug.Log("Mouse is over: " + hit.collider.name);
}

Screen Shots (Mouse is in middle above cross hair): enter image description here enter image description here

Meer
  • 2,765
  • 2
  • 19
  • 28
OT2O
  • 129
  • 2
  • 3
  • 8
  • 1
    I see you have several `GameObjects` names "Camera" in your scene. Do you have multiple cameras with the tag "MainCamera." You should only have one if you plan on using `Camera.main` as that will return the first one it finds with that tag – Foggzie Mar 03 '17 at 02:13
  • No I only have one mainCamera, I have gotten this issue when referencing the camera component specifically as well. – OT2O Mar 03 '17 at 20:04

1 Answers1

0

Not sure what is the problem(provide more details) but your code snippet working fine for me.(I test it without vive but with steam camera rig prefab). Here is the snap of my scene

enter image description here

Remember, you have to click first in game view in order to view the right direction of ray.

Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186