- Home /
GetAxisRaw("Mouse X") not even close to manual mouse movement
I try to create my own mouse movement but I don't understand why Unity's Input manager has completely different results than mine.
Unity's Input Manager
Vector2 MouseMovement { get { return new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y")); } }
My first attempt
Vector3 mouseMove;
Vector3 prevPos;
void UpdateMouseInp()
{
Vector3 mousePosition = Input.mousePosition;
mouseMove = mousePosition - prevPos;
prevPos = mousePosition;
}
My second attempt
private class Import
{
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X, Y;
public static implicit operator Vector2(POINT point)
{
return new Vector2(point.X, point.Y);
}
}
[DllImport("user32.dll")]
public static extern bool GetCursorPos(out POINT lpPoint);
public static Vector2 GetCursorPosition()
{
POINT lpPoint;
GetCursorPos(out lpPoint);
return lpPoint;
}
}
Vector3 mouseMove;
Vector3 prevPos;
void UpdateMouseInp()
{
Vector3 mousePosition = Import.GetCursorPosition();
mouseMove = mousePosition - prevPos;
prevPos = mousePosition;
}
All three methods give completely different result, first and second attempts vary between 1 and 2.5 times the scale of Unity's Input Manager. And my first attempt just misses a lot movement, sometimes even for 10 frames.
Why are my attempts way off Unity's Input Manager mouse movement? And which is more accurate, My second attempt or Unity's Input Manager?
Your answer
Follow this Question
Related Questions
Object.OnMouseDown vs Input.GetMouseButtonDown 1 Answer
Multiple Players on one Computer/Console 5 Answers
Touch inputs on a Desktop type device 2 Answers
What's the entry name for mouse buttons in InputManager? 2 Answers
How to disable mouse click detection in game when clicking exit menu button? 1 Answer