Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 $$anonymous$$ · Mar 21, 2019 at 06:04 AM · cursor

Get mouse's pixel position on the monitor, independent of the game window's position or size.

I need to to simply know the mouse's position, where 0,0 is at the bottom left corner of the whole monitor, and not the bottom left corner of the game window.

I could calculate the position of the mouse by checking the Input.MousePosition, plus some calculations that factor in the screen resolution and the game window's x/y position on the screen...

However that is particularly tricky in my case, because I'm also moving my whole game window based on the cursor's movement. This creates a whip-lash effect since the game window is moving based on the cursor's position, while simultaniously I'm trying to calculate the cursor's position based on the game window's position! You see the problem.

I've actually managed to fix the whip lash by predicting the whiplash and compensating for it, but I'd still like to know why the bloody heck it isn't possible to simply get the mouse's X and Y position on the whole monitor? Or is it possible though a windows DLL call or something?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Vollmondum · Mar 21, 2019 at 07:42 AM

Game window is simply a preview of what you get in actual game. Whole monitor = game window when the game is built and running.

Comment
Add comment · Show 2 · 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 $$anonymous$$ · Mar 22, 2019 at 04:26 PM 0
Share

Umm... Whole monitor is not the same as game window. The game can run in a window, which isn't necessarily the size of the whole monitor.

avatar image Vollmondum $$anonymous$$ · Mar 23, 2019 at 12:17 PM 0
Share

Yeah, that's called outsmarting :) I answered whatever I suppose he needed. Well, at least people with such questions don't go that deep into coding as windowed games.

avatar image
0

Answer by Casiell · Mar 22, 2019 at 08:11 PM

Input gives you mouse position in screen coordinates. Unity Camera has two methods that will do what you want ScreenToWorldPoint and ScreenToViewportPoint

Comment
Add comment · Show 2 · 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 $$anonymous$$ · Mar 24, 2019 at 07:56 PM 0
Share

You are wrong. None of these things do anything remotely close to giving the position of the mouse relative to the corner of the whole monitor, where the position isn't affected by the position of the game window.

avatar image Casiell $$anonymous$$ · Mar 25, 2019 at 03:06 PM 0
Share

Sorry, I misread the question.

avatar image
0

Answer by $$anonymous$$ · Mar 25, 2019 at 10:58 PM

I discovered that GetCursorPos (which is a user32.dll call) will actually give correct mouse position... but only if you (a) have windows mouse acceleration turned off (which requires you to edit the registry), and (b) have window's text and application scaling set to exactly 100% in control panel, and (c) have windows pointer speed set to exactly 50% in the window's mouse settings, and (d) have the game window set to scaling of exactly 1.0x (if you are running it in the unity editor mode).... so yea.. it works but sure has a lot of conditions. I'd still like to just have the mouse position without all those conditions, but I guess if it was easy then Unity would have already been giving it to us through Input. I just wish I knew how AutoHotKey gets the mouse position so accurately and easily, there must be a way, Unity dev's must just not know how to do it I guess.

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

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

103 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

first person - hide mouse 1 Answer

UNITY3D: Custom cursors? 3 Answers

Cursors and crosshairs 1 Answer

Problem Button Click with Cursor, Cursor attach the gameobject 2 Answers

How do you select an object with the cursor and retrieve data from that object selected? 1 Answer


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