Mouse position from new InputSystem is not correct and is not the same as Input.mousePosition
Hello Unity community,
I've migrated to UnityEngine.InputSystem package and have had mouse position problems ever since.
When I create a new 2D project and add a simple script with
using UnityEngine;
public class MouseInputTest : MonoBehaviour {
void OnDrawGizmos() {
var mousePosition = Input.mousePosition;
Gizmos.DrawCube(Camera.main.ScreenToWorldPoint(mousePosition), Vector3.one);
}
}
All works as expected and the gizmo is shown correctly at the mouse position.
However if I import the InputSystem package and use the following code
using UnityEngine;
using UnityEngine.InputSystem;
public class MouseInputTest : MonoBehaviour {
void OnDrawGizmos() {
var mousePosition = Mouse.current.position.ReadValue();
Gizmos.DrawCube(Camera.main.ScreenToWorldPoint(mousePosition), Vector3.one);
}
}
The Y coordinate of mouse position vector (Mouse.current.position.ReadValue()) is inverted (for example it's value is 10 instead of -10). And X coordinate seems offset by camera width to the left.
This is all with default project settings. Any idea why this happens? Am I doing something wrong? Couldn't find any help in the forums or documentation.
I guess it can be "fixed" by manually inverting the Y and offsetting X, but it seems weird.
Any help is appreciated.
Your answer
Follow this Question
Related Questions
Please help me with my mouse pointer 0 Answers
How to control global mouse 0 Answers
Bullet to Mouse Position? 1 Answer