Search Unity

OculusGo OVRInput model doesn't detect hits past 90º angles (on the same object)

Discussion in 'VR' started by ShadownHeart, Jan 8, 2019.

  1. ShadownHeart

    ShadownHeart

    Joined:
    Oct 8, 2015
    Posts:
    29
    Hello!
    As the tittle says, I've got a button that follows the user head movements (it's on the center of the view). The hit detection works perfectly until the user turns the head more than 90º to the left/right.

    I don't know why or where is this problem located.

    I've done some debugging on OVRInputModule.cs so far, and the eventSystem.RaycastAll stops detecting hits pass 90º angle.

    Code (CSharp):
    1.  virtual protected MouseState GetGazePointerData()
    2.         {
    3.             // Get the OVRRayPointerEventData reference
    4.             OVRPointerEventData leftData;
    5.             GetPointerData(kMouseLeftId, out leftData, true );
    6.             leftData.Reset();
    7.             //Now set the world space ray. This ray is what the user uses to point at UI elements
    8.             leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward);
    9.             leftData.scrollDelta = GetExtraScrollDelta();
    10.             //Populate some default values
    11.             leftData.button = PointerEventData.InputButton.Left;
    12.             leftData.useDragThreshold = true;
    13.             // Perform raycast to find intersections with world
    14.             eventSystem.RaycastAll(leftData, m_RaycastResultCache);
    15.  
    16. [B]//// RESULT HERE TURN TO 0 WHEN 90º IS PASSED
    17.             Debug.Log(m_RaycastResultCache.Count);
    18. ////[/B]
    19.  
    20.             var raycast = FindFirstRaycast(m_RaycastResultCache);
    21.             leftData.pointerCurrentRaycast = raycast;
    22.             m_RaycastResultCache.Clear();
    Any ideas?
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Hmm, tricky. Oculus's code does have a number of bugs, and generally makes everything more complex than it needs to be. But writing your own input module is very thorny too, so you probably don't want to do that if you can help it.

    Can you verify that the worldSpaceRay still seems sensible even when turned?

    If so, then I guess the problem must be in the other parts of leftData. Possibly the parts filled in by GetPointerData. I remember stumbling across some really dumb code somewhere in the Oculus input stuff that filled in a bogus screen position, because the event system required it — the requirement is not their fault, but their solution was poor. Unfortunately I don't remember the details, and am not in a position to check right now.

    So here's hoping this gives you a useful nudge in the right direction... if not, let me know and I'll try to dig up my version of the code.
     
  3. ShadownHeart

    ShadownHeart

    Joined:
    Oct 8, 2015
    Posts:
    29
    Hi! I tried to look for the oculus methods but I found nothing.
    GetPointerData doesn't seems to do something related to the hit detection that could be the cause of the problem.

    Code (CSharp):
    1.   protected bool GetPointerData(int id, out OVRPointerEventData data, bool create)
    2.         {
    3.             if (!m_VRRayPointerData.TryGetValue(id, out data) && create)
    4.             {
    5.                 data = new OVRPointerEventData(eventSystem)
    6.                 {
    7.                     pointerId = id,
    8.                 };
    9.  
    10.                 m_VRRayPointerData.Add(id, data);
    11.                 return true;
    12.             }
    13.             return false;
    14.         }
    An then, the ray is working properly (I think), it turns with the camera.

    Code (CSharp):
    1.             //Now set the world space ray. This ray is what the user uses to point at UI elements
    2.             leftData.worldSpaceRay = new Ray(rayTransform.position, rayTransform.forward);
    3.             leftData.scrollDelta = GetExtraScrollDelta();
    4.             //Populate some default values
    5.             leftData.button = PointerEventData.InputButton.Left;
    6.             leftData.useDragThreshold = true;
    Maybe something wrong related to this step:
    Code (CSharp):
    1.  eventSystem.RaycastAll(leftData, m_RaycastResultCache);

    I also think that has to be something on the "lefData", but I cannot find anything, for now.
    I'll keep debugging looking for a clue.
     
  4. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    My guess is that the problem is related to the following:
    • in OVRInputModule.GetGazePointerData, there is a step that assigns leftData.position = ovrRaycaster.GetScreenPosition(raycast). Comments there claim the Unity UI system expects event data to have a screen position.
    • GetScreenPosition is calling eventCamera.WorldToScreenPoint on the raycast result's world position.
    That's going to be bogus if the ray is not actually within the screen as seen by eventCamera.

    So I would start by double-checking... are you certain your event camera is the same one as the main camera (i.e. the one creating the view the user sees)?

    After that, I'd check each of those steps to make sure you're getting valid results.
     
  5. ShadownHeart

    ShadownHeart

    Joined:
    Oct 8, 2015
    Posts:
    29
    Okey, it was the camera. Thank you so much!
    I was assigning the wrong camera to some of my canvas (with a script that I implemented to automate some process), my bad.
     
    JoeStrout likes this.
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Awesome! Thanks for following up to let us know what it was. Hopefully this thread will be found by the next guy to make the same simple mistake.
     
    ShadownHeart likes this.