fix: PlayerInput now normalizes input after un/pause

This commit is contained in:
Sara 2025-07-25 13:29:00 +02:00
parent 5d0ae90fbc
commit 10535a675d
2 changed files with 28 additions and 3 deletions

View file

@ -1,4 +1,5 @@
#include "player_input.h"
#include "scene/main/scene_tree.h"
String PlayerInput::sig_movement_input{ "movement_input" };
String PlayerInput::sig_look_input{ "look_input" };
@ -20,13 +21,33 @@ void PlayerInput::_bind_methods() {
ADD_SIGNAL(MethodInfo(sig_crouch, PropertyInfo(Variant::BOOL, "is_crouching")));
}
void PlayerInput::normalize_input() {
emit_signal(sig_movement_input, Vector2());
emit_signal(sig_look_input, Vector2());
emit_signal(sig_primary_fire, false);
emit_signal(sig_alt_mode, false);
emit_signal(sig_run, false);
emit_signal(sig_crouch, false);
}
void PlayerInput::_notification(int what) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
if (what == NOTIFICATION_READY) {
switch (what) {
case NOTIFICATION_READY:
set_process(true);
set_process_unhandled_input(true);
Input::get_singleton()->set_mouse_mode(Input::MouseMode::MOUSE_MODE_CAPTURED);
return;
case NOTIFICATION_PROCESS: {
bool const is_paused{ get_tree()->is_paused() };
if (is_paused != this->was_paused) {
this->was_paused = is_paused;
callable_mp(this, &self_type::normalize_input).call_deferred();
}
return;
}
}
}

View file

@ -6,6 +6,7 @@
class PlayerInput : public Node {
GDCLASS(PlayerInput, Node);
static void _bind_methods();
void normalize_input();
void _notification(int what);
virtual void unhandled_input(Ref<InputEvent> const &event) override;
@ -18,6 +19,9 @@ public:
static String sig_run;
static String sig_jump;
static String sig_crouch;
private:
bool was_paused{ false };
};
#endif // !PLAYER_INPUT_H