|
I'm doing some basic GUI manipulation with the mouse and I'm getting some weird behavior like the GUI element I'm moving not being exactly where the mouse pointer is. I'm using ScreenToViewportPoint to convert the mouse position to viewport space and I'm finding that it's not precise enough. It only returns values to like 0.3 instead of 0.332, for example. If there any way to get more floating point accuracy?
(comments are locked)
|
|
i was doing stuff with mouse and GUI stuff a while ago, found that some somethings convert stuff to different orientations. specifically inverting the y value, the origin will either be in the top left or bottom right, so try just multiplying a Y value by -1 However I cant remember off the top of my head what does the orientation in the bottom right, but i think the GUI stuff uses top left most the time The problem is that standard microsoft C# pixel-based locations are backwards. Y=0 is on TOP, with positive Y going down. Code-based guis -- Viewport (0-1) puts Y=0 on the bottom and positive Y going up, like normal. Likewise Input.MousePosition uses Y=0 on bottom with pixels going up (also normal.) I believe that ViewPortToScreen gives you the "good" system, with y=0 on the bottom, like it should be, and ScreenToViewPort assumes Y=0 is the bottom with Y going up. The fix, to go from "correct" Y-bottom screen to "Y=0 top and plus Y goes down", is to use
Sep 23 '11 at 05:01 PM
Owen Reynolds
I really don't see how this could have any relevance to grayfox's question.
Sep 23 '11 at 09:41 PM
Waz
(comments are locked)
|
|
i am also having problems with unprecize mouseposition -.- i want my player to shoot where the mouse is, but a lot of times it shoots wrong cause of this... and i dont really want to scale my hole world by 10 or 20 -.-, Don't use an answer to someone else's question to ask a question. The original question was wrong anyway - ScreenToViewportPoint is not inaccurate.
Apr 06 '12 at 09:05 PM
Waz
(comments are locked)
|

What makes you believe it only returns numbers like 0.3? If that was the case, there would only be 10 positions across the screen. Note that Vector3.ToString only shows an approximate value, so if your belief comes from using Debug.Log or print, it is just those functions fooling you.