I started making a game with unity 5.3.5f1 long ago. Now that I am more or less satisfied with how it works, I tried to implement InputManager in it, and an strange issue happened.
Long story short, I implemented moving with arrow keys during development. More or less like this:
// I set variables like this, then use them to compute movement
if(Input.GetKey(KeyCode.UpArrow)) {
upDownInput = 1;
}
if(Input.GetKey(KeyCode.DownArrow)) {
upDownInput = -1;
}
// Similar for the other two keys, but with a variable called "leftRightInput"
It works fine. And, when I am not inputting any direction, the player (a sphere) keeps it’s inertia no matter if I turn the camera or not (just the way I want it). From there I tried to implement InputManager for the sake of genericity.
However, if I change the “if conditions” like this:
if(Input.GetAxis("Vertical") > 0) { // <- UpArrow key
upDownInput = 1;
}
if(Input.GetAxis("Vertical") < 0) { // <- DownArrow key
upDownInput = -1;
}
// Similar with horizontal axis
It works well. However, without touching Arrow keys (both Axis == 0), if I turn the camera, the inertia changes depending on direction of camera!
I just don’t understand why this happens. It is too weird!! How is possible that the way I get the input makes such a dramatic change? The rest of the code (which actually controls ball movement) is still the same!
Is there someone that may have any clue why such anomaly happens?