• 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 ina · Jan 02, 2011 at 01:12 PM · inputmousecoordinatesviewport

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

cursor is off

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
1
Best Answer

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.

Comment
Add comment · Show 4 · 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 ina · Jan 03, 2011 at 02:16 AM 0
Share

Do you notice that this GUITexture btn is not aligned with the mouse, or is it just me?

avatar image Eric5h5 · Jan 03, 2011 at 04:09 AM 0
Share

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.

avatar image ina · Jan 03, 2011 at 12:25 PM 0
Share

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..

avatar image ina · Jan 03, 2011 at 12:26 PM 0
Share

Eric: you ROC$$anonymous$$ ... lol i need to just ask you things before everythingelse

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How do I get the x and y coordinates out of Input.mousePosition? 2 Answers

return float value for mouse input +/-Y 2 Answers

Force MouseButtonUp on Android 0 Answers

Character Zoom in and out 1 Answer

Is there a built-in function to determine if any GUI item has been clicked? 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges