Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent axis-based actions from getting stuck #81170

Merged
merged 1 commit into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,18 +701,39 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em

if (!p_event->is_echo()) {
if (p_event->is_action_pressed(E.key)) {
action.pressed++;
if (jm.is_valid()) {
// If axis is already pressed, don't increase the pressed counter.
if (!action.axis_pressed) {
action.pressed++;
action.axis_pressed = true;
}
} else {
action.pressed++;
}

is_pressed = true;
if (action.pressed == 1) {
action.pressed_physics_frame = Engine::get_singleton()->get_physics_frames();
action.pressed_process_frame = Engine::get_singleton()->get_process_frames();
}
} else {
if (action.pressed == 1) {
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
action.released_process_frame = Engine::get_singleton()->get_process_frames();
bool is_released = true;
if (jm.is_valid()) {
// Same as above. Don't release axis when not pressed.
if (action.axis_pressed) {
action.axis_pressed = false;
} else {
is_released = false;
}
}

if (is_released) {
if (action.pressed == 1) {
action.released_physics_frame = Engine::get_singleton()->get_physics_frames();
action.released_process_frame = Engine::get_singleton()->get_process_frames();
}
action.pressed = MAX(action.pressed - 1, 0);
}
action.pressed = MAX(action.pressed - 1, 0);
}
action.exact = InputMap::get_singleton()->event_is_action(p_event, E.key, true);
}
Expand Down
1 change: 1 addition & 0 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Input : public Object {
uint64_t released_physics_frame = UINT64_MAX;
uint64_t released_process_frame = UINT64_MAX;
int pressed = 0;
bool axis_pressed = false;
bool exact = true;
float strength = 0.0f;
float raw_strength = 0.0f;
Expand Down