Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
avatar image
1
Question by M1xelatedd · Aug 02, 2015 at 08:08 AM · ratio

Raycast has offset when build is not in native aspect ratio

Raycast has offset when build is not in native aspect ratio (only in full screen mode) I have a script that adds black bars. However I am using mouseposition in raycast to find the position. Basically when the resolution has a different aspect ratio than 16:9 it creates 4:3 with black bars which somehow works for some resolution but when the scaling is too much it fails to work making me unable to click on gameobjects. Raycast script:

///////////////////////////////////

 void CastRayOne() {
 Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
 RaycastHit hit;
         if (Physics.Raycast (ray, out hit, 100)) {
             Debug.DrawLine (ray.origin, hit.point);
             Debug.Log ("Hit object: " + hit.collider.gameObject.name);
             if(hit.collider.gameObject.tag == "Character"){
                 CharacterHelper.SetActive(false);
                 CustomizerText_Character.text = hit.collider.gameObject.name;
             Instantiateposition = new Vector3(hit.collider.transform.position.x+2,hit.collider.transform.position.y,hit.collider.transform.position.z);
             Instantiatedobject = (GameObject)Instantiate (Customizer_Character,Instantiateposition,Customizer_Character.transform.rotation);
             Instantiatedbool = true; 
             TempChar = hit.collider.gameObject; 
             }




Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by frederik_krogh · Sep 18, 2020 at 06:29 PM

same problem.. If you could read the aspect ratio u could add the error margin to the mouse pointer and get the right result..

Comment
Add comment · Show 1 · Share
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 frederik_krogh · Sep 18, 2020 at 06:33 PM 0
Share

I mean, my native resolution is 1920x1200 but i force the player to go 1920x1080 in the player settings. I can see that i uses raycast for the native resolution (1920x1200) instead of the players resolution. This means that when i push a button the raycast returns a slightly offset position. I can get the right value if i add the extra valu to the mouseposition.. It must be a bug.. I think unity reads the mouseposition directly from the machine and puts it into the player without transfor$$anonymous$$g it even if the player is scaled. $$anonymous$$akes no sense

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Restricting ratio of a 2D Game 2 Answers

Resolution 2 Answers

LOD - Shape of boundary for transition LOD0/LOD1/LOD2/ 0 Answers

Whats the best practice to draw GUI control buttons? 0 Answers

How do I remove the extra tiles in the right and bottom 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