Search Unity

Raycast forward from vr camera sometimes not centered in view?

Discussion in 'Daydream' started by Ice52, Oct 20, 2016.

  1. Ice52

    Ice52

    Joined:
    Feb 24, 2015
    Posts:
    2
    I already posted this on the main unity forum, but this seems like a more appropriate place for it.

    http://answers.unity3d.com/questions/1258833/unity-daydream-preview-raycastcamera-alignment.html

    I've just rebuilt my Google Cardboard game using the Unity Daydream Preview, Previously I was using a recent version of the Google VR SDK.

    I am using a raycast forward from the camera to determine the users gaze and allow interaction with objects via staring at them (actually just a slightly modified VREyeRaycaster from the VR standard assets: https://www.assetstore.unity3d.com/en/#!/content/32351)..

    During testing I noticed that sometimes I needed to gaze above or below the object before it would register the raycast collision. It was as if the ray or hitboxes had been moved relative to the camera.

    It seems to be consistent throughout the scene once it had been loaded (e.g. I always have to look slightly above all the objects, by about the same amount, to trigger the action).

    It also seems to be linked to the orientation of the phone when you load the scene, (or possibly the whole game), if I load things with the phone in landscape as if in the headset, the raycast seems to be aligned, if I load things with the phone flat on the desk or at a 45 degree angle that is when it is way off.

    Any ideas what might be going on?

    P.S. I've uploaded the version to google play as a public beta if you want to take a look:

    https://play.google.com/apps/testing/uk.co.softkitty.puzzleroom
     
    Last edited: Oct 20, 2016
  2. thep3000

    thep3000

    Unity Technologies

    Joined:
    Aug 9, 2013
    Posts:
    400
    My *guess* is that you may be using Screen.width / 2 and Screen.height / 2 to find the center point of the screen to raycast from.

    The eye texture sizes don't match the screen size, so this point will be wrong. Try using VRSettings.eyeTextureWidth / 2 and VRSettings.eyeTextureHeight / 2 as the screenspace raycast origin.
     
    guneyozsan likes this.
  3. Ice52

    Ice52

    Joined:
    Feb 24, 2015
    Posts:
    2
    Thanks, I've checked, but I am using the camera transform to determine the origin of the ray:

    Ray ray = new Ray(m_Camera.position, m_Camera.forward);

    Think I may have found the answer though.

    I was using my own "neck" script to update the camera transform based on the rotation, (in the version of the Google VR SDK I was using previously, this was missing). After disabling this, the problem disappeared.

    The camera view still seemed to be moving as if there was a neck though, so I suspect this has been put back into the SDK. My guess is maybe it's doing the Raycast from my transform to the camera, but rendering the view from a separate transform in the SDK... Or before my transform is applied or something like that.

    I still don't quite understand why its affected by the orientation of the phone when initialising the level, but I think the lesson for me is don't update the camera transform in your own scripts.
     
    Last edited: Oct 21, 2016