gdquest-demos / godot-make-pro-2d-games

A-RPG demo made with Godot, MIT-licensed, from our Godot course
MIT License
995 stars 108 forks source link

Fixed axis inputs clashing with discrete inputs #87

Closed codeinclined closed 6 years ago

codeinclined commented 6 years ago

I've noticed with some of my own projects that mixing axis inputs with other types of input in a single action (such as "move_left") can cause the two to "fight" each other. It mostly happens when you hold down a key for an action that also has an axis assigned to it. Randomly, you could just lose the state of the key being pressed until you lift the key and press it again. Other times, it can just ignore the keypress altogether. I think it's a timing-specific thing with the engine's input code if the analog sensor in the gamepad momentarily exceeds its deadzone (which can happen, especially with noisier sensors).

I saw this behavior occurring right away when I first ran this project and implemented a simplified version of the fix I did in one of my own projects to get around this issue. Basically, actions with axis inputs are split into two actions. I named these "discrete_move_left", "joy_move_left", etc. I called the keyboard version "discrete" rather than "key" as a pattern. The only thing needed to fix this issue is to keep axes separate from discrete inputs. You could add D-Pad buttons to the discrete actions alongside the keyboard without any issues. I didn't do so here only because I didn't know if we had something in mind for the D-Pad in the future.

Just to reiterate, not all actions will need duplicate actions for joypad. Only actions with axis inputs seem to cause problems. This may not have been an issue for most people, but if I'm encountering this across multiple projects and versions of Godot, then it might also affect others in the future.

codeinclined commented 6 years ago

I forgot to create a branch for my changes. I don't want to mess up the merging history of the repo, so I opened #89