- Home /
why input isn't working correctly?
Curious to know what could be affecting my keyboard input. I made some scripts to control movements and actions for a 2D game using the 2017.3.1f1 unity editor.
For several hours I've tried debugging my issue, which is: after pressing a jump key another key press isn't getting evaluated. I made a counter after the Input.GetButtonDown call just to be sure and it doesn't count until after he player has hit ground again. It doesn't occur with any other inputs, just after the "Jump". I also found some code to log the keys pressed and stored 10 key presses to a string and logged it, same results.
I did notice that if constantly jumping around eventually the button press does get returned, but the issue returns immediately after stopping.
Just for kicks, I plugged in my Xbox controller and had no issue whatsoever, and my scripts function as expected. Is my computer doing this, or what might be going on?
I just now checked the primary positive Fire1, and it also works as expected. The alt (mouse0) button is the one presenting the symptom.
Any help understanding this would be greatly appreciated.
Thanks
Chances are it's your keyboard not working properly, could you post your script here?
Answer by uwakaronai · Jan 25, 2021 at 07:40 PM
@john_unity389 Thanks for replying. Unfortunately, I don't have internet. I will post what I can and shorthand it where possible. I know I should be using a desktop for this but you get by with what you got. My mouse is a touchpad. It just seems weird how the problem manifested, unless it was getting conflicting input that has no keyCode from the mouse.
No worries if you don't want to continue reading this. But, if you're interested in questioning my scripts, I can give you an idea what they do. Bear in mind, I'm a noob and I'm not crunching to finish a project just trying to get better at programming an understand how unity works, so I may doing things that can be done more easily with the GUI purposely.
I basically have three scripts to control player movement, animations, and actions. They talk to each other a little bit. -The movement script stores a string of the base layer animation state, which has idle walking jumping or falling.
[NonSerialized] string baseState="idle"; Update(){ProcessInputs} ProcessInputs(){ If (condition){baseState="walking" }else{baseState="idle"; }}
-The actions script stores 2 strings, one for the action of the input and one for the layer that the animation state is on. I'm not sure if it's the way I want the animations controlled yet.
[NonSerialized] string layer="base"; [NonSerialized] string "idle"; Update(){ ProcessInputs(); SetToBase(); } ProcessInputs(){ If (Input.GetButtonDown("Fire1")){ action="throw"; layer="arms"; }else if (layer !="base"){ action="idle"; }} SetToBase(){ if (action=="idle"){ layer="base"; }}
-The animator script takes the state name from the movement script and the layer and action from the actions script in update. It plays the state if the layer is not the base layer, otherwise it plays the state from the movement script.
Start and Update()- use getcomponent<>() for the NonSerialized variables. activeLayer = layer from actions action = from actions state = base state from movement
Animate(){ If( activeLayer !="base){ anim.Play(action, anim.GetLayerIndex(activeLayer)); }else{ anim.Play(state); }}
I used a separate state behavior script on the action state to set the layer weight to 1 and 0 respectively on enter and exit for the animation state.
Thanks, Ben
Sorry, didn't realize the enter key wouldn't make a new line.
Your answer
Follow this Question
Related Questions
C# Mouse Look (Input.GetAxis("MouseX&Y")) 0 Answers
Create new InputManager entry? 2 Answers
Touch inputs on a Desktop type device 2 Answers
Baffling Input.Mouseposition problem. If statement not correctly working. 1 Answer
How to Move a Cube 3 Answers