diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2018-05-01 11:15:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-01 11:15:51 +0200 |
| commit | 5281415a7b6a7b5f2a43c6ee5a43721dd08aee14 (patch) | |
| tree | ad54183e957578f29048ad1aab3736c91f537210 /core/os/input_event.cpp | |
| parent | 8852ca14550d367947dfda2246865d50faa36bbe (diff) | |
| parent | 0aa8b35ee689fc8b3813ab3d35c85f9cf97775a9 (diff) | |
Merge pull request #18428 from groud/fix_input
Fixing input strength and the impossibility to erase action events
Diffstat (limited to 'core/os/input_event.cpp')
| -rw-r--r-- | core/os/input_event.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 5003be77ab..4ebb821a2f 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -656,12 +656,14 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * if (jm.is_null()) return false; - bool match = (axis == jm->axis && (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0)); + bool match = (axis == jm->axis); // Matches even if not in the same direction, but returns a "not pressed" event. if (match) { + bool same_direction = (((axis_value < 0) == (jm->axis_value < 0)) || jm->axis_value == 0); + bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false; if (p_pressed != NULL) - *p_pressed = Math::abs(jm->get_axis_value()) >= p_deadzone; + *p_pressed = pressed; if (p_strength != NULL) - *p_strength = (*p_pressed) ? Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())) : 0.0f; + *p_strength = pressed ? CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f) : 0.0f; } return match; } |