i started a new project, added a plane with boxcollider.
Then i added an empty gameobject with character controler, rigidbody and capsule collider and this script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class characterControl : MonoBehaviour
{
void Update()
{
Debug.Log(Input.GetAxis("Vertical"));
}
}
Now i would expect the console to start puting out zero’s, but instead i am getting -1’s…
I am not pressing any keys. What can be causing this behavior?? I never had this happening before?
even in an empty scene, adding an empty gameobject, put above script on it. it shows -1 until you click stop and then it gives me 5 update loops when it resets to 0 … i am puzzled…
This axis grabs input from joysticks, so my first guess is that you have a joystick/controller plugged in which is erroneously thinking it’s being held down (or, Unity/your drivers erroneously think it is). So first question is, do you have anything like that plugged in? You can also go into Project Settings → Input, find the Vertical axis, and change “Joy Num” to some other value, see if that changes this.
In my case, this was exactly it, an old XBOX gamepad that sometimes decides on its own vertical axis has value of -0.084 and thus brutally destroys my wall-sliding mechanic.
But since it’s here anyway, that’s exactly why “deadzones” are a thing. It is perfectly normal for peripherals to not return actual zeroes in their idle state, for a variety of reasons: imperfect calibration, electrical noise, wear / damage, component tolerances, and so on. From memory, the official recommendation for the Xbox 360 controller was to use a 15% or 20% deadzone. And that makes a lot of sense if you pick up one of those controllers and touch the stick lightly - it wiggles a bit before there’s any resistance or centering spring at all, so a player could let go of the stick and it won’t return exactly to the center.
I can’t remember if the similar numbers were recommended for the outside limit as well, but it can definitely also be done. In serious simulators this is often all exposed to the player, so that they can tweak it to the specific tolerances of their equipment.
The general idea is that instead of using raw input data, you clamp input magnitudes to a range of, say, [0.15, 0.85] and then remap that back to a range of [0, 1]. This way your software ignores the signal ranges where the hardware is least likely to be reliable.
Many games also apply a curve to that remapping, which is a major contributor to how a game’s controls feel.