- Home /
XBox Controller Joystick-Driven Mouse Cursor in Unity
Hi everyone,
Thank you for reading this thread. I am currently building a 2D game (fixed camera view from a distance) that requires to control mouse cursor using Xbox Controller joystick. The professor instructs me not to using 3rd party software and I have experienced the controller in 3D by changing the values in Input Manager's Axis (this 3D game has a camera behind an object I controll), and it worked out fine.
However, my case is that the mouse cursor has to follow XBox controller's movement and it is in 2D. Therefore, how am I supposed to do that? What should be changed in Mouse object's script or inspector? Thank you.
Note: Remember that it is fixed camera view from a distance, I just want to have the mouse cursor controllable by XBox controller joystick. Also, I don't have Unity Pro, just the free version. Thank you again.
first you might need this https://github.com/speps/XInputDotNet
then you need to make a fake mouse, one that will react both Joystick and $$anonymous$$ouse movements.
first use this
Screen.showCursor = false;
this will disable the default cursor. you want this so it doesnt interfere.
then
//Pseudo code
Vector2 XboxOffset = Vector2.zero;
Vector3 $$anonymous$$y$$anonymous$$ousePosition = Input.mousPosition + XboxOffset;
void Update() {
XboxOffset = new Vector2("your joystic information goes here)
$$anonymous$$y$$anonymous$$ousePosition = Input.mousPosition + XboxOffset;
GUITexture.pixelInset = $$anonymous$$y$$anonymous$$ousePosition
}