- Home /
Can I reset the InputManager's Axes with a script?
By default, the Horizonal Axis in the InputManager is set to the right key is positive and the left key is negative. If you hold down the left key, the value of the Axis goes down to -1 and then stays there as long as you hold down the left key.
Is there any way to tell the InputManager to reset itself, and ignore any keys that may be held down? For instance, if someone was holding down the left key, and the Horizontal Axis was at -1, just resetting the Horizontal Axis to 0 and ignoring the left key until it's released and pressed again?
Follow up question: if it isn't possible, is it possible to "spoof" an Input.GetKeyUp event on a specific key? Can you tell Unity the left key was lifted even if it wasn't?
What was wrong with Input.ResetInputAxis();
? I'm assu$$anonymous$$g something was, since it's the top result from searching "unity reset input."
The scripting docs says it snaps to 0's, and something about buttons for only 1 frame. But the text implies it clears a held-down button. I've never tested it.
What was wrong with the answer button? Is it just more fun to knock down newbs in the comment section? And we'll have to agree to disagree on the first results for "unity reset input", my first results are:
http://answers.unity3d.com/questions/471506/how-to-reset-games-built-input-controls.html http://answers.unity3d.com/questions/213986/how-to-reset-users-input-settings.html http://answers.unity3d.com/questions/35477/how-can-i-restore-input-settings.html
$$anonymous$$aybe that's why I asked a question, on this question and answer site.
Finally: there is no ResetInputAxis. There IS a ResetInputAxes, which resets ALL axes (plural). Fortunately that'll still work for me, so thanks for letting me know about it! If only there was some way I could give you credit or appreciation for answering a question I had. Oh well.
Answer by iamMichaelDavis · Feb 06, 2014 at 04:58 PM
Input.ResetInputAxes(); will reset all the Axes to 0
(thanks to Owen Reynolds for the answer :) )
Answer by FunkyL1zard · Feb 05, 2014 at 03:57 PM
I'm not sure that you can reset the InputManager's Axes, however you can use Input.GetMouseButtonDown and Input.GetMouseButtonUp instead of it. You can Invoke a action that will do something even if the mouse button is still down.
float delay; // Delay before Activity is called
void Update(){
if(Input.GetMouseButtonDown(0)){
Invoke("Activity", delay)
}
if(Input.GetMouseButtonUp(0)){
Activity();
}
}
void Activity(){
}
The Activity will still be called even if you don't release the mouse button.
I was running into a bug in my beginner's first try state machine I made where if you pressed the right key (`Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.RightArrow);`) my player character would start walking right, and the amount it would move would be multiplied by the amount of the input:
transform.Translate (Vector2.right * Input.GetAxis ("Horizontal") * egoSpeed * Time.deltaTime);
And every update the state machine checks to see if the key is still down (`Input.Get$$anonymous$$ey ($$anonymous$$eyCode.RightArrow);`) and if it is it keeps walking right. Once you let go of the right key, the walking stops, and it begins to listen for key press events again.
However, if you press and hold right, THEN press and hold left, then let go of the right button, my player stops walking, but the held down left key sets the Horizontal axis to -1. When you press right again (still holding left) the "walk right" animation begins, but the player's direction is multiplied by -1, making him moonwalk.
With Input.ResetInputAxes();
running when the right key is released (`Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.RightArrow);`), the input is reset when you let go of the right key, and the very next frame the game assumes the held down left key is just now being pressed, and turns the character left.
Your answer
Follow this Question
Related Questions
Get list of Axes? 4 Answers
Steelseries 3gc controller key mappings 0 Answers
Button Axis with New Input System 0 Answers
Will Unity 3.0 have a scriptable Input Manager 1 Answer
Make ball flip around cube... 0 Answers