Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here:
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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


    Sep 23, 2014
    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


    Aug 17, 2012
    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