Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Our response to Improbable’s blog post (and why you can keep working on your SpatialOS game). Read more here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

AR raycast misplaced when viewport rect is modified

Discussion in 'Handheld AR' started by citizen_12, Jan 11, 2019 at 9:19 PM.

  1. citizen_12


    Jun 21, 2013
    Playing with the arfoundation-samples project. Decided to add a UX panel that is always visible on the screen, so I created a second UX camera and changed the viewport rect of the AR Camera to only draw the top 75% of the screen (i.e. Y=0.25 instead of Y=0). The UX camera uses the bottom 25%.

    Problem is that now my touches in the AR view are all offset vertically by the height of the UX view. Are we supposed to transform the touch ourselves before passing it to Raycast?

    Attached Files:

  2. tdmowrer


    Unity Technologies

    Apr 21, 2017
    There are two versions of the raycast interface.
    • One takes a
      . The ray is specified in world space, so it is independent of the camera's viewport.
    • The other takes a
      , actually a 2 dimensional screen space value between (0,0)-(screen width, screen height). This you would need to transform as it assumes the AR camera image takes up the entire screen.
    The easiest thing to do would probably be to use the first version of the Raycast interface (the one that takes a Ray) and pass it a ray from Camera.ScreenPointToRay.