Search Unity

Question CameraRays in VR (Basic Question)

Discussion in 'VR' started by Cooleobrad, May 22, 2020.

  1. Cooleobrad

    Cooleobrad

    Joined:
    Dec 16, 2016
    Posts:
    15
    I was looking at the Unity documentation page for Camera Rays https://docs.unity3d.com/Manual/CameraRays.html and I had a question regarding the line:
    Ray ray = camera.ScreenPointToRay(Input.mousePosition);
    If I'm looking to just have a simple raycast centered to the camera to select items on a menu screen for example, what should "mousePosition" be replaced with since I won't be using a mouse in VR? Or will it work normally to leave that specifier in?

    Thanks!
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    No, you'll have to use something else. If you really want a ray through the center of the screen (which you shouldn't want; you should instead cast a ray from one or both hands), you would use Camera.ViewportPointToRay.
     
  3. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,933
    Unless you're doing gaze-selection? In that case I guess you'd use this ... although I'd be tempted to still try and do a raycast from the in-world controller / XRNode object, so that I could re-use the same code on my "head" controller and "hands" controllers.

    i.e. Physics.Raycast( node.transform.position, node.transform.forward, ... ) or something like that.