Home > Net >  Problem with ScreenToWorldPoint when using multiple monitors [Solved]
Problem with ScreenToWorldPoint when using multiple monitors [Solved]

Time:11-10

I'm programming a top-down shooter game with an orthographic cam and everything works fine, when I'm using only one monitor. But as soon as i start the game with both monitors in extension mode(one 1920x1200 and the other 1366x768), the position of the mouse in world units is wrong.

This is the funktion,that I use to convert pixel positions into World units: Camera.main.ScreenToWorldPoint(Input.mousePosition);

The resolution of the currently used monitor and the pixel position of the mouse is measured correctly. The offset between the real position of the cursor and the measured position in world units grows as I move my cursor away from a point slightly right of the lower left corner (at this position (ca. at 180,0 pixel position) the measured and real cursor position are the same). The problem also doesn't occur, if i start the game before i plug in my second monitor.

Thanks in advance!

CodePudding user response:

Solution:

Screen.currentResolution was detecting the right resolution, but Camera.main.pixelWidth and Camera.main.pixelHeight (wich is used by Camera.main.ScreenToWorldPoint(Input.mousePosition);)were detecting the resolution of the not used monitor for some reason

  • Related