- Home /
ScreenToViewportPoint offset from Input.mousePosition ?
ScreenToViewportPoint seems like it has an offset from the coords returned from mousePosition. How do you anticipate this offset or somehow make the btn right under the mouse cursor?
If you run the snippet below, you'd see that the btn is not right under the mouse cursor but off at a distance.
var btn:GameObject; var cam:Camera;
function Start(){ btn=GameObject.Find("btn"); cam=GameObject.Find("Camera").camera; } function Update () { btn.transform.position=cam.ScreenToViewportPoint(Input.mousePosition); }
in screenshot below, btn is the red gui element. evidently, it is offset from the mousePosition
Answer by Eric5h5 · Jan 02, 2011 at 06:06 PM
It's not offset. Assuming "btn" is an object that uses viewport coords (GUIText/GUITexture), it's positioned exactly like you'd expect.
Do you notice that this GUITexture btn is not aligned with the mouse, or is it just me?
You're doing something else to cause that. The code you have is fine and there is no offset. $$anonymous$$ight be pixel inset values.
it was the pixel insets -- well, that was a 3-sec solution to about 3 hours of $$anonymous$$ring things apart thinking something else went wrong..
Eric: you ROC$$anonymous$$ ... lol i need to just ask you things before everythingelse
Your answer
Follow this Question
Related Questions
How do I get the x and y coordinates out of Input.mousePosition? 2 Answers
Erratic mouse Input.GetAxis values on OS X 0 Answers
Switch Between Touch And Mouse Controls 0 Answers
Input.inputString not detecting mouse action? 1 Answer
Unity3D mouse events not working on Amazon Web Services EC2 instance in Play mode 0 Answers