Fix NaN with get_action_strength

(cherry picked from commit 3bfa080c9c)
This commit is contained in:
Gilles Roudière 2019-05-15 11:21:10 +02:00 committed by Rémi Verschelde
parent 53eb140cf1
commit dcc9c1cc2a
1 changed files with 11 additions and 2 deletions

View File

@ -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; bool pressed = same_direction ? Math::abs(jm->get_axis_value()) >= p_deadzone : false;
if (p_pressed != NULL) if (p_pressed != NULL)
*p_pressed = pressed; *p_pressed = pressed;
if (p_strength != NULL) 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 (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; return match;
} }