Search Unity

World Space Canvas that stays same size in VR

Discussion in 'AR/VR (XR) Discussion' started by TaylorCaudle, Mar 20, 2020.

  1. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    10
    Trying to create a destination marker, I had it working properly in non-VR with Screen Space overlay, accurately shows the markers and their distance from the player,

    But in VR screen space doesnt work accurately. So im trying to basically set the objects up in World Space, render them over everything, and keep them the same size regardless of distance (so theyll stay the same size if the players far away or close).

    Anyone have any tips on how to do this?
     
  2. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    589
    What do you mean by "doesn't work accurately"?
     
  3. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    10
    I mean the Screen Space UI in a non-VR scene worked properly with the script, it kept the UI marker locked to the distant position of the target, and displayed accurate distance from the player

    but when switching to the Oculus OVR player camera in my main scene, setting the screenspace camera to the Center Eye, the UI doesnt show in the right places. it seems to hover far above me in the sky, seemingly tracking SOMETHING, but not the right targets, and they move- but not with the camera, i think the player position.

    Either way, screen space VR ui seems to only work when locked to the POV, like a HUD. Trying to see if anyone has had any luck getting something like a navigation marker to work in VR
     
  4. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    589
    Ah, right. Probably your tracking code is making assumptions about the camera matrix and failing to account for different camera setups - in a screenspace camera you can get away with a lot of bugs and mistakes and because the camera is of a very simple projection you won't notice it's wrong (it'll map to exactly the same space as if the code were correct). The OVR cameras are non-trivial.

    Do you especially want to use screenspace canvas? Most are using world-space for UI, for a bunch of reasons. (e.g. one I was looking at recently: Oculus likes to blur anything that's not directly in front of your eye, to significantly increase performance ... which means you want UI to either be locked in world space (player can move their head to focus on it better), or slide based on head tilt (which is really easy to do on a world space canvas and not so easy on a screenspace one), so I don't think many people will have experience with what you're trying here.)

    Personally ... I would ditch the screenspace canvas and do it in world space. Tracking objects etc is super easy in world space ... off the top of my head:
    1. fire a ray from camera origin to target object
    2. intersect the ray with the world-space camera's plane (using Unity's built-in Plane object which does all the work for you)
    3. use the camera's built-in WorldToScreenSpace method to find the position on the camera
    4. ... draw or position your GUI at that point.
     
    JoeStrout likes this.
  5. TaylorCaudle

    TaylorCaudle

    Joined:
    Feb 8, 2018
    Posts:
    10


    Yeah, that was the gist of my question lol- trying use World Space UI to mark a location, and just keep the canvas size the same regardless of distance, so itll always be there in the HUD basically.

    Just having some trouble finding the right resources for the scripts, but i just wanted to know if it was doable!
     
unityunity