- Home /
Ignore Xbox 360 controller joystick when it re-centers (returns to 0),Xbox 360 joystick input returning to 0
In my FPS game, I am trying to move a crosshair with my right joystick. The problem I am running into is that the read input of the joystick always returns to 0 when the it re-centers. I want the crosshair to move as I move the joystick and then stop when I release it, and not go back (snap) to the center of the screen or where the movement started. I am currently used Input.GetAxis("Horizontal").
I believe lots of games do this with their cameras and crosshairs. the game reads the joystick input when moving but then ignore it when returning to center. Below is my Code
void Update () {
float hAxis = Input.GetAxisRaw("AimJoystickHorizontal");
float vAxis = Input.GetAxisRaw("AimJoystickVertical");
Vector2 stickInput = new Vector2(vAxis * 30, hAxis * 30);
// Here, I am just trying to formulate a good deadzone value
if (stickInput.magnitude < deadzone)
stickInput = Vector2.zero;
else
stickInput = stickInput.normalized * ((stickInput.magnitude - deadzone) / (1 - deadzone));
Rotation = Quaternion.Euler(stickInput.x, stickInput.y, 0);
//This is How I transform the crosshair
crosshair.transform.position = cameraFacing.transform.position +
cameraFacing.transform.rotation * Rotation * Vector3.forward * distance ;
Answer by nomadic · Jun 18, 2018 at 07:43 PM
Check out the settings for the Horizontal axis input in InputManager. https://docs.unity3d.com/Manual/class-InputManager.html
Try playing with Gravity, Sensitivity, and Dead. Most notably, Gravity will allow you to increase the snappiness, or how quickly the axis value will return to zero.
Gravity option doesn't apply when the input is read from a joystick axis. I am already content with the sensitivity and dead values. I just want the input to ignore the joystick returning to center. just like what happens in games when the controller's joystick is used to move the camera. The camera moves when you push the joystick but then doesn't return to it's original position when the joystick re-centers.
Wait, how are you applying axis input to your camera rotation? If you add rotation to the camera based on axis input then it should work like you describe.
Sorry, I should've included my code from the beginning. It's updated now. The last part is how I apply the rotation.