- Home /
Input.GetAxis values returning to neutral in an inconsistent way?
I have a game where the engine of the craft needs to be rotated in the direction of thrust. The code all works fine except the values from Input.GetAxis seem to return to neutral in an odd way. This causes the rotation to change as the force is calculated directly from these inputs. I looked into the Axis settings such as Gravity and Sensitivity but these are at the defaults and changes I make don't seem to affect the returning behaviour consistency.
Here's the code:
force_delta.x = Input.GetAxis("Horizontal");
if (Mathf.Abs(force_delta.x) < 0.1f)
force_delta.x = 0;
force_delta.y = Input.GetAxis("Vertical");
if (Mathf.Abs(force_delta.y) < 0.1f)
force_delta.y = 0;
So if I hold up/right for example, then hold down/left, then let go of the keys, the drop back to neutral for force_delta results in an incorrect rotation angle being set. That's just an example, I can't really make out a specific pattern yet. Hopefully that makes sense.
The code for calculating rotation is smoothdamped etc but essentially the angle is calulated with:
float angle = Mathf.Atan2(force_delta.y, force_delta.x) * Mathf.Rad2Deg;
Normalizing the force doesn't seem to help either, in fact if anything it makes it worse. I think this may be a unity bug but has anyone else has this problem and/or know a solution?
Your answer
![](https://koobas.hobune.stream/wayback/20220613073638im_/https://answers.unity.com/themes/thub/images/avi.jpg)