Lowers "pressed" threshold when emulating a button via controller joysticks. #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
When using some external controllers (in my case, an Xbox One S controller), the cDown and cRight mappings did not work during emulation.
As it turns out, when mapping a continuous input (for instance, a joystick) to a discrete input (for instance, a button), a value of
1
is considered pressed, and any value less than 1 is considered not-pressed.This would be fine in an ideal world, where controllers send a range of [-1, 1] for both the x and y axis. That is what the code expects, and once the joystick is extended all the way to the edge in any direction, it registers an absolute-value of
1
, resulting in a press for whatever button is mapped to that direction.Annoyingly, my controller actually sends a range of about [-.99, 1], meaning that even when I extend the joystick all the way to some edges, it's about
.01
away from actually registering a click.Solution:
Apply some rounding to any values being sent to a discrete input. This means that the press will register after a value of
0.5
, which happens when the joystick is moved halfway to the edge.Possible Future Improvements:
0.5 might not be the optimal threshold for registering a press. It's a bit subjective, but something closer to 0.8 might be more comfortable for some players.
This logic might belong "lower" in the stack -- for instance, in a particular
emulatorBridge.activateInput()
implementation.