diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-05-15 11:34:24 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-15 11:34:24 +0200 |
commit | 27a3557a75403ccd2b3f57541902d72edec3a4b5 (patch) | |
tree | 90babfbef7ed09ac2c126f0578defeb02b155701 /core | |
parent | dc7a40f00519ba681233d1513f634e4a464095b5 (diff) | |
parent | 3bfa080c9c6ac13b20670b04d58692aad08fb99b (diff) |
Merge pull request #28902 from groud/fix_nan_strength
Fix NaN with get_action_strength
Diffstat (limited to 'core')
-rw-r--r-- | core/os/input_event.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 25a5c2afeb..a072017353 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -717,8 +717,17 @@ bool InputEventJoypadMotion::action_match(const Ref<InputEvent> &p_event, bool * bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false; if (p_pressed != NULL) *p_pressed = pressed; - if (p_strength != NULL) - *p_strength = pressed ? CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f) : 0.0f; + if (p_strength != NULL) { + if (pressed) { + if (p_deadzone == 1.0f) { + *p_strength = 1.0f; + } else { + *p_strength = CLAMP(Math::inverse_lerp(p_deadzone, 1.0f, Math::abs(jm->get_axis_value())), 0.0f, 1.0f); + } + } else { + *p_strength = 0.0f; + } + } } return match; } |