Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Laurence_Lee · Jan 12, 2017 at 04:40 PM · camerascreenray

Inconsistency Result of ScreenPointToRay between UnityEditor and Real Device

Hi, I've suffered from a wired exception. this part of test code runs out inconsistent results

     Transform camera_trans = GameManagers.CameraMgr.SceneCamera;
     if (camera_trans == null) return "";
     Camera camera = camera_trans.GetComponent<Camera>();
     Vector3 screen_pos = Vector3.zero;
     screen_pos.x = 960.0f;
     screen_pos.y = 540.0f;

     Ray touchRay = camera.ScreenPointToRay(screen_pos);
     Debugger.Log("CameraPos:" + camera_trans.position.ToString());
     Debugger.Log("RayCastTo3DObj:" + screen_pos.ToString() + " " + touchRay.ToString());

On UnityEditor, this will print

     0:4:7.448-277: CameraPos:(-25.4, 58.3, -343.6)
     0:4:7.448-277: RayCastTo3DObj:(960.0, 540.0, 0.0) Origin: (-25.4, 58.3, -343.5), Dir: (0.0, -0.3, 0.9)

On RealDevice(an un-exploded Samsung Galaxy 3), adb logs

     0:4:7.448-277: CameraPos:(-25.4, 58.3, -343.6)
     0:4:7.448-277: RayCastTo3DObj:(960.0, 540.0, 0.0) Origin: (-25.4, 58.3, -343.5), Dir: (0.4, -0.1, 0.9)

the resolution is 1920*1080 (double checked on Real Device) Is there any other factors of camera which may affect the result of the ray, when I send in same inputs?

BTW: Unity version 5.4.0b20

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image hexagonius · Jan 12, 2017 at 10:25 PM 0
Share

if you're using a perspective camera, this result is expected. make it orthographic and it's the same result.
it's because of the different aspect ratios the editor and the device are using. since the camera view in perspective mode is like a fan, the ray direction is slightly different

avatar image Laurence_Lee hexagonius · Jan 13, 2017 at 04:31 AM 0
Share

First of all, thx 4 ur answer. However, perspective camera is a must in my project.

In fact, I'm working on click-select. The ray calculated on UnityEditor leads to correct result(means I can click on the screen and the ray collides the exact gameobject I wanna select), but the results on real device leads to a wired performance because of the inconsistent ray direction. Is there any approach to make it work correctly on real device ? $$anonymous$$aybe I need some more coordinator transition before I send the screen pos into camera?

avatar image hexagonius Laurence_Lee · Jan 13, 2017 at 08:59 AM 0
Share

I can't see you using any touch or mouse position, is that in a different script?

avatar image Laurence_Lee · Jan 13, 2017 at 07:06 AM 0
Share

Fixed! It's still a resolution issue.

Our guys on 3D/Render redefined the resolution of rendering buffer without adjusting the resolution(in fact, game resolution is 1920*1080 but 3D resolution is auto configured by device 1344*756) So the screen pos is not approciate to the 3D camera resolution. After adapting the screen pos to camera resolution, everything goes fine.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Screen Space - Camera makes bullets fly in wrong directions 1 Answer

converto text to texture2D 0 Answers

Where is the screen within a camera's frustum? 0 Answers

Frustrating problem with UI canvas (lines of canvas flicker around the edges of screen in game!!!) 5 Answers

UI GameObjects showing in scene view but not game view? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges