Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by lodendsg · Sep 15, 2013 at 05:02 AM · guiraycastscreenpointtoray

Raycast behavies as if its snapping to grid on standalone build

I am using raycast to locate a GameObject in worldspace i.e. I am casting a ray from my UI camera and taking its hit.point as the new location for my object.

This works nice and smooth when ran in the editor however when I build and test in stand alone the object moves as if its snapping to a grid.

I set up a few messages to see the results of the case; in editor I see [Note gradual change to the y value]

Mouse @749,949 cursor move to 9992.822,10070.4,10108.08

Mouse @751,950 cursor move to 9993.35,10070.61,10108.08

Mouse @754,952 cursor move to 9993.983,10070.93,10108.08

in build I see [Note the 3+/- unit change in the y value]

Mouse @887,993 cursor move to 9994.194,10054.46,10108.08

Mouse @887,994 cursor move to 9994.194,10057.95,10108.08

Mouse @887,995 cursor move to 9994.194,10057.95,10108.08

Mouse @887,996 cursor move to 9994.194,10057.95,10108.08

Mouse @887,997 cursor move to 9994.194,10057.95,10108.08

Mouse @887,998 cursor move to 9994.194,10057.95,10108.08

Mouse @887,999 cursor move to 9994.194,10057.95,10108.08

Mouse @887,1000 cursor move to 9994.194,10057.95,10108.08

Mouse @887,1001 cursor move to 9994.194,10057.95,10108.08

Mouse @887,1002 cursor move to 9994.194,10057.95,10108.08

Note from mouse.y 993 to 994 the world pos moved 3.9 units; from 995 to 1002 it didnt move at all. The plane I am aiming at is 109 units out from the camera and for this test level with the camera such that the object should move up and down, left and right but not in and out.

Code in question


 Ray ray = MainCamera.ScreenPointToRay(Input.mousePosition);
               RaycastHit hit;
              if(Physics.Raycast(ray, out hit, CursorLayers))
             {
                 CursorPosition.transform.position = hit.point;
                 Debug.Log("Mouse @" + Input.mousePosition.x.ToString() + "," + Input.mousePosition.y.ToString() + " cursor move to " + hit.point.x.ToString() + "," + hit.point.y.ToString() + "," + hit.point.z.ToString());
             }



I have tested the build at a number of diffrent resolutions the exsact results are diffrent but always jumps by a couple of units while the in editor run always moves smooth.

I'll keep digging on it my self but any pointers or tips would be much appreciated.

Thanks

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 lodendsg · Sep 15, 2013 at 05:03 AM 0
Share

Had a hard time getting that to post; looks like some of the formatting got trashed; let me know if you need more info

avatar image lodendsg · Sep 15, 2013 at 01:34 PM 0
Share

Ran another test so I could visualize the hit.point locations; in this test I generate a cube with no collision mesh at the hit.point. I am calling 1000 ray casts via an invoked method to fire the 1000 ray casts each 1 pixel right from the last at 500 pixels up the screen; the result should be a solid line accross the screen and that is what we get in the editor however at run time we get a dashed line.

In editor In Editor example

In stand alone build In run time

in editor run.jpg (28.5 kB)
buildtime.jpg (21.5 kB)
avatar image lodendsg · Sep 15, 2013 at 02:50 PM 0
Share

@meat5000 Thanks for the clean up on the formating thing was giving me a hard time.

avatar image meat5000 ♦ · Sep 15, 2013 at 02:55 PM 0
Share

No problem :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by lodendsg · Sep 15, 2013 at 02:32 PM

Found the answer;

The casue of this behaviour is the near clip; I had set my GUI camera near to 0.01f; did this so that objects passing through the screen wouldnt get cliped till the last second draw back is that rays are cast from the near through the pixel location of the mouse and apparently to only 2 points of perision which causes them to hop on a grid that is roughly 100 by 100 (I'm guessing) when the near is set to 0.01;

I adjusted my near to be as far out as I can tollerate for this camera and everything smoothed right out. Now why this causes the in accuracy in the ray cast in the build but not the editor I'm not sure.

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 lodendsg · Sep 15, 2013 at 02:45 PM 0
Share

For note this also cleaned up an accuracy issue I had where in my 3D GUI I have a couple of render to texture cameras and I am passing my ray cast hit texture cords and casting a second ray on the render to text camera which also had the near clip set to 0.01f.

The default of 0.3f works moderetly Im guessing this gives a grid of 300 by 300 when I adjust to 3.0f I get nice smooth behaviour above 5 and accuracy starts to fall again below 1 also isnt so smooth.

To see exsactly whats going on I used DrawRay; zoom in or set your near clip low and you will see it bounce around.

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

16 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

Related Questions

Get GUITexture to follow ScreenPointToRay ray cast 1 Answer

Why does ScreenPointToRay bug when called from IEnumerators? 1 Answer

How to get raycast hit coordinates on Cardboard 0 Answers

GUI display weapon name you are looking at 1 Answer

Drag gui text and drop it on 3d object. 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