Search Unity

  1. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

[Unity 5.6.1] Determine "Center of Screen" for Raycasting

Discussion in 'AR/VR (XR) Discussion' started by Selzier, Jun 14, 2017.

  1. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    644
    In all previous versions of Unity, "Center of Screen" can be determined by calling either this for non-vr mode:
    Code (CSharp):
    1. new Vector2(0.5f * Screen.width, 0.5f * Screen.height);
    Or using EyeTextureWidth/Height when VR Mode is enabled:
    Code (CSharp):
    1. new Vector2(0.5f * (float)VRSettings.eyeTextureWidth, 0.5f * (float)VRSettings.eyeTextureHeight);
    Now, in Unity 5.6.1, neither one of these will return the correct "center of screen" position as needed for raycasting with gaze-based interaction.

    How can we determine "Center of screen" with VR Mode enabled in Unity 5.6.1+?

    I've tried both Cardboard and GearVR builds, with no success. Thanks!
     
  2. greggtwep16

    greggtwep16

    Joined:
    Aug 17, 2012
    Posts:
    1,546
    I haven't noticed anything broken with 5.6.1 for either gaze raycasting or controller laser pointer raycasting. Are you having issues with graphics raycasts or physics raycasts? Also can you show the code for the actual raycast as well?

    Edit: Just reviewed my code for graphics raycasting and for the part above I use:

    Code (CSharp):
    1. pos = new Vector2(UICamera.pixelWidth * 0.5f, UICamera.pixelHeight * 0.5f);
     
    Last edited: Jun 14, 2017
unityunity