feat: joypad controls

This commit is contained in:
Sara Gerretsen 2026-04-27 15:14:46 +02:00
parent da01bf25d4
commit 755db4c926
2 changed files with 30 additions and 5 deletions

View file

@ -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<InputEvent> 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();
}
}

View file

@ -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)
]
}