Add some controller controls

This commit is contained in:
Sofia 2026-08-07 19:53:10 +03:00
parent 9ffceb55db
commit 387778b9ec
5 changed files with 118 additions and 50 deletions

View File

@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://7iooamjot1tg"]
[ext_resource type="PackedScene" uid="uid://dov2eh5u4ypnx" path="res://scenes/misc/health_pickup.tscn" id="2_yffox"]
[ext_resource type="Script" uid="uid://cijpblptlwvs" path="res://maps/scripts/test.gd" id="3_e0nj3"]
[ext_resource type="PackedScene" uid="uid://c1r8nk58cci3a" path="res://scenes/misc/goal.tscn" id="4_w7til"]
[sub_resource type="ImageTexture" id="ImageTexture_3vyb7"]
@ -17,6 +18,16 @@ size = Vector3(1000, 1, 1000)
[sub_resource type="BoxShape3D" id="BoxShape3D_1cgct"]
size = Vector3(100, 0.01, 100)
[sub_resource type="BoxShape3D" id="BoxShape3D_w7til"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vwb5y"]
[sub_resource type="BoxMesh" id="BoxMesh_8af6u"]
material = SubResource("StandardMaterial3D_vwb5y")
[sub_resource type="BoxShape3D" id="BoxShape3D_oqkce"]
size = Vector3(5, 5, 5)
[node name="map" type="Map" unique_id=914577955 node_paths=PackedStringArray("spawners", "ball_spawner")]
spawners = [NodePath("team1_spawner"), NodePath("team2_spawner")]
ball_spawner = NodePath("ball_spawner")
@ -61,3 +72,25 @@ collision_mask = 7
shape = SubResource("BoxShape3D_1cgct")
[node name="health_pickup" parent="static_body_3d/collision_shape_3d" unique_id=1860192333 instance=ExtResource("2_yffox")]
[node name="triggerable" type="Triggerable" parent="." unique_id=1334645267 node_paths=PackedStringArray("mesh")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -10.587965, 3.0791914, -9.513515)
script = ExtResource("3_e0nj3")
mesh = NodePath("mesh_instance_3d")
[node name="shootable_trigger" type="ShootableTrigger" parent="triggerable" unique_id=785877778]
[node name="collision_shape_3d" type="CollisionShape3D" parent="triggerable/shootable_trigger" unique_id=1335150803]
shape = SubResource("BoxShape3D_w7til")
[node name="mesh_instance_3d" type="MeshInstance3D" parent="triggerable" unique_id=1224898916]
mesh = SubResource("BoxMesh_8af6u")
[node name="proximity_trigger" type="ProximityTrigger" parent="triggerable" unique_id=957182227]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.7171593, -2.5604024, 0.8731904)
[node name="collision_shape_3d" type="CollisionShape3D" parent="triggerable/proximity_trigger" unique_id=329578045]
shape = SubResource("BoxShape3D_oqkce")
[connection signal="on_shot" from="triggerable/shootable_trigger" to="triggerable" method="activate" unbinds=2]
[connection signal="on_trigger" from="triggerable/proximity_trigger" to="triggerable" method="activate"]

View File

@ -1,19 +1,8 @@
[gd_scene format=3 uid="uid://c5p0ft870i1sk"]
[ext_resource type="PackedScene" uid="uid://dpqqe7hjktit8" path="res://maps/two_towers/two_towers_static.scn" id="2_l5vmt"]
[ext_resource type="Script" uid="uid://cijpblptlwvs" path="res://maps/scripts/test.gd" id="3_vwb5y"]
[ext_resource type="Script" uid="uid://diepa0rcedh5f" path="res://maps/meta/map_rebuilder.gd" id="4_y3aqj"]
[sub_resource type="BoxShape3D" id="BoxShape3D_1cgct"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_vwb5y"]
[sub_resource type="BoxMesh" id="BoxMesh_1cgct"]
material = SubResource("StandardMaterial3D_vwb5y")
[sub_resource type="BoxShape3D" id="BoxShape3D_3g557"]
size = Vector3(5, 5, 5)
[node name="two_towers" type="Map" unique_id=590524284 node_paths=PackedStringArray("spawners", "ball_spawner")]
spawners = [NodePath("two_towers_static/func_godot_map/entity_11_info_spawn_point"), NodePath("two_towers_static/func_godot_map/entity_5_info_spawn_point")]
ball_spawner = NodePath("two_towers_static/func_godot_map/entity_1_info_spawn_point")
@ -22,25 +11,3 @@ ball_spawner = NodePath("two_towers_static/func_godot_map/entity_1_info_spawn_po
script = ExtResource("4_y3aqj")
[node name="two_towers_static" parent="." unique_id=86902040 instance=ExtResource("2_l5vmt")]
[node name="triggerable" type="Triggerable" parent="." unique_id=1206596848 node_paths=PackedStringArray("mesh")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 33.152664, 3.0791912, 0)
script = ExtResource("3_vwb5y")
mesh = NodePath("mesh_instance_3d")
[node name="shootable_trigger" type="ShootableTrigger" parent="triggerable" unique_id=306909670]
[node name="collision_shape_3d" type="CollisionShape3D" parent="triggerable/shootable_trigger" unique_id=298869370]
shape = SubResource("BoxShape3D_1cgct")
[node name="mesh_instance_3d" type="MeshInstance3D" parent="triggerable" unique_id=174590790]
mesh = SubResource("BoxMesh_1cgct")
[node name="proximity_trigger" type="ProximityTrigger" parent="triggerable" unique_id=774677471]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.7171593, -2.5604024, 0.8731904)
[node name="collision_shape_3d" type="CollisionShape3D" parent="triggerable/proximity_trigger" unique_id=1090850563]
shape = SubResource("BoxShape3D_3g557")
[connection signal="on_shot" from="triggerable/shootable_trigger" to="triggerable" method="activate" unbinds=2]
[connection signal="on_trigger" from="triggerable/proximity_trigger" to="triggerable" method="activate"]

View File

@ -67,41 +67,49 @@ toggle_cli={
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)
]
}
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)
]
}
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)
]
}
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":0,"pressure":0.0,"pressed":false,"script":null)
]
}
shoot={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null)
]
}
pause={
"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":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
]
}
scoreboard={
"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":4194306,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":true,"script":null)
]
}
open_chat={
@ -112,11 +120,13 @@ open_chat={
weapon_1={
"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":49,"key_label":0,"unicode":49,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":9,"pressure":0.0,"pressed":true,"script":null)
]
}
weapon_2={
"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":50,"key_label":0,"unicode":50,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":10,"pressure":0.0,"pressed":true,"script":null)
]
}
swap_weapon_up={
@ -132,21 +142,45 @@ swap_weapon_down={
punch={
"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":70,"key_label":0,"unicode":102,"location":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":2,"pressure":0.0,"pressed":true,"script":null)
]
}
throw_telegrenade={
"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":81,"key_label":0,"unicode":113,"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)
]
}
next_spectator={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":true,"script":null)
]
}
prev_spectator={
"deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":2,"canceled":false,"pressed":false,"double_click":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":13,"pressure":0.0,"pressed":true,"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_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_down={
"deadzone": 0.2,
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
]
}

View File

@ -292,6 +292,15 @@ fn set_bus_volume(bus: &str, volume: f32) {
}
fn set_keybind(action: &str, keybind: Keybind) {
InputMap::singleton().action_erase_events(action);
for event in InputMap::singleton()
.action_get_events(action)
.iter_shared()
{
if event.clone().try_cast::<InputEventKey>().is_ok()
|| event.clone().try_cast::<InputEventMouseButton>().is_ok()
{
InputMap::singleton().action_erase_event(action, &event);
}
}
InputMap::singleton().action_add_event(action, &keybind.into_event());
}

View File

@ -114,6 +114,8 @@ pub struct LocalPlayer {
buffs: Buffs,
just_shot: bool,
base: Base<CharacterBody3D>,
}
@ -614,6 +616,15 @@ impl ICharacterBody3D for LocalPlayer {
if self.buffs.update(delta) {
self.buffs.clone().update_effects(self);
}
if self.just_shot {
if Input::singleton()
.get_action_strength("shoot")
.is_zero_approx()
{
self.just_shot = false;
}
}
}
fn input(&mut self, event: Gd<InputEvent>) {
@ -663,12 +674,13 @@ impl ICharacterBody3D for LocalPlayer {
}
}
if event.is_action_pressed("shoot") {
if event.is_action_pressed("shoot") && !self.just_shot {
if let Some(pos) = self.raycast_from_camera() {
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
match peer {
PeerKind::Client(peer, addr) => {
if self.try_shoot(pos, false, true) {
self.just_shot = true;
peer.send_reliable(
addr,
Shoot(0, pos.into(), self.get_transform(), self.look_up),
@ -677,6 +689,7 @@ impl ICharacterBody3D for LocalPlayer {
}
PeerKind::Server(peer, _) => {
if self.try_shoot(pos, true, true) {
self.just_shot = true;
peer.broadcast_reliable(Shoot(
self.player_id.unwrap_or(0),
pos.into(),
@ -757,26 +770,21 @@ impl ICharacterBody3D for LocalPlayer {
}
if let Ok(event) = event.try_cast::<InputEventMouseMotion>() {
if !self.is_dead() {
let x = event.get_relative().x * 0.001 * self.look_sensitivity;
let y = event.get_relative().y * 0.001 * self.look_sensitivity;
if let Some(camera) = self.camera.as_mut() {
let curr_rotation = camera.get_rotation();
let x_rot =
(curr_rotation.x - y * self.look_sensitivity).clamp(-PI / 2., PI / 2.);
camera.set_rotation(Vector3::RIGHT * x_rot);
self.look_up = x_rot;
}
let y_rot = -x * self.look_sensitivity;
self.y_rot = self.base().get_global_rotation().y + y_rot;
}
self.move_look(event.get_relative())
}
}
}
fn physics_process(&mut self, delta: f64) {
let input = Input::singleton();
let joypad_look_dir = Vector2::new(
input.get_action_strength("look_right") - input.get_action_strength("look_left"),
input.get_action_strength("look_down") - input.get_action_strength("look_up"),
) * 5.;
if !joypad_look_dir.is_zero_approx() {
self.move_look(joypad_look_dir);
}
let rot = self.y_rot;
let new_rot = Vector3 {
y: rot,
@ -903,6 +911,23 @@ impl LocalPlayer {
mat.set("shader_parameter/Color", &color.to_variant());
}
}
fn move_look(&mut self, direction: Vector2) {
if !self.is_dead() {
let dir = direction * 0.001 * self.look_sensitivity;
if let Some(camera) = self.camera.as_mut() {
let curr_rotation = camera.get_rotation();
let x_rot =
(curr_rotation.x - dir.y * self.look_sensitivity).clamp(-PI / 2., PI / 2.);
camera.set_rotation(Vector3::RIGHT * x_rot);
self.look_up = x_rot;
}
let y_rot = -dir.x * self.look_sensitivity;
self.y_rot = self.base().get_global_rotation().y + y_rot;
}
}
}
#[godot_dyn]