From 755db4c926c9b86cc0888f240ad9cf205a73bbd3 Mon Sep 17 00:00:00 2001 From: Sara Date: Mon, 27 Apr 2026 15:14:46 +0200 Subject: [PATCH] feat: joypad controls --- modules/viscosity/player_camera.cpp | 10 +++++----- project/project.godot | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/modules/viscosity/player_camera.cpp b/modules/viscosity/player_camera.cpp index 3f9fd8f1..775eb28f 100644 --- a/modules/viscosity/player_camera.cpp +++ b/modules/viscosity/player_camera.cpp @@ -12,7 +12,7 @@ void PlayerCamera::_bind_methods() { void PlayerCamera::update_rotation() { this->rotation += Vector2{ -this->mouse_look_input.x, this->mouse_look_input.y } * 0.0016f; - this->rotation += this->joystick_input; + this->rotation += this->joystick_input * get_process_delta_time(); static float const lim{ Math::PI / 2.f - 0.1f }; this->rotation.y = CLAMP(this->rotation.y, -lim, lim); this->mouse_look_input = { 0.f, 0.f }; @@ -61,11 +61,11 @@ void PlayerCamera::unhandled_input(Ref const &event) { if (motion.is_valid()) { this->mouse_look_input = motion->get_relative(); get_viewport()->set_input_as_handled(); - } else if (event->is_action("look_horizontal")) { - this->joystick_input.x = event->get_action_strength("look_horizontal"); + } else if (event->is_action("look_right") || event->is_action("look_left")) { + this->joystick_input.x = Input::get_singleton()->get_axis("look_right", "look_left"); get_viewport()->set_input_as_handled(); - } else if (event->is_action("look_vertical")) { - this->joystick_input.y = event->get_action_strength("look_vertical"); + } else if (event->is_action("look_down") || event->is_action("look_up")) { + this->joystick_input.y = Input::get_singleton()->get_axis("look_up", "look_down"); get_viewport()->set_input_as_handled(); } } diff --git a/project/project.godot b/project/project.godot index 251724cf..c2f97a1d 100644 --- a/project/project.godot +++ b/project/project.godot @@ -24,25 +24,50 @@ config/icon="res://icon.svg" move_left={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":-1.0,"script":null) ] } move_right={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null) ] } move_forward={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":-1.0,"script":null) ] } move_backward={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":1,"axis_value":1.0,"script":null) ] } jump={ "deadzone": 0.2, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":3,"pressure":0.0,"pressed":true,"script":null) +] +} +look_left={ +"deadzone": 0.2, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) +] +} +look_right={ +"deadzone": 0.2, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) +] +} +look_up={ +"deadzone": 0.2, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null) +] +} +look_down={ +"deadzone": 0.2, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) ] }