From 276ff0252bbef6d7b1c9915c5a9efed077220aa1 Mon Sep 17 00:00:00 2001 From: Rendo Date: Wed, 26 Nov 2025 23:04:24 +0500 Subject: [PATCH] crouch fixed --- scenes/player.tscn | 212 ++++++++++++---------- scripts/debug/property_shower.gd | 21 +++ scripts/debug/property_shower.gd.uid | 1 + scripts/player/states/crouching.gd | 8 +- scripts/player/states/standing.gd | 5 +- scripts/player/states/walk.gd | 4 +- scripts/state_machine/machine.gd | 17 +- scripts/state_machine/state.gd | 2 + scripts/state_machine/substate_machine.gd | 7 + scripts/weapon_system/gun/idle_state.gd | 2 +- scripts/weapon_system/weapon_system.gd | 3 + 11 files changed, 167 insertions(+), 115 deletions(-) create mode 100644 scripts/debug/property_shower.gd create mode 100644 scripts/debug/property_shower.gd.uid diff --git a/scenes/player.tscn b/scenes/player.tscn index 922bbf1..fa37929 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -8,6 +8,7 @@ [ext_resource type="Script" uid="uid://bmecgup3kcua7" path="res://scripts/weapon_system/weapon_system.gd" id="4_qlg0r"] [ext_resource type="Script" uid="uid://dd5mp72dq43v6" path="res://scripts/multiplayer/own_visibility_toggle.gd" id="4_smehm"] [ext_resource type="PackedScene" uid="uid://djwjl8xll53vn" path="res://scenes/weapons/starting_pistol.tscn" id="7_fjrip"] +[ext_resource type="Script" uid="uid://7gmgcaxfh8sb" path="res://scripts/debug/property_shower.gd" id="7_oprun"] [ext_resource type="Script" uid="uid://3777rkbebgjm" path="res://scripts/state_machine/machine.gd" id="8_f1ej7"] [ext_resource type="PackedScene" uid="uid://c2r8dbudbs7l3" path="res://models/molikman_ingame.glb" id="8_smehm"] [ext_resource type="Script" uid="uid://bv8sgx78s8hwn" path="res://scripts/player/states/crouching.gd" id="9_oprun"] @@ -16,94 +17,7 @@ [ext_resource type="Script" uid="uid://cq4i0afwesdm3" path="res://scripts/player/states/falling.gd" id="12_fulsm"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_u8vuu"] - -[sub_resource type="Animation" id="Animation_g2els"] -resource_name = "Crouch" -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("CollisionShape3D:shape:height") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0, 1), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [2.0, 1.5] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("CollisionShape3D:position") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0, 1), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Vector3(0, 1, 0), Vector3(0, 0.75, 0)] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath("Camera3D:position") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0, 1), -"transitions": PackedFloat32Array(1, 1), -"update": 0, -"values": [Vector3(0, 2, 0), Vector3(0, 1.5, 0)] -} - -[sub_resource type="Animation" id="Animation_dqkch"] -length = 0.001 -tracks/0/type = "value" -tracks/0/imported = false -tracks/0/enabled = true -tracks/0/path = NodePath("CollisionShape3D:shape:height") -tracks/0/interp = 1 -tracks/0/loop_wrap = true -tracks/0/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [2.0] -} -tracks/1/type = "value" -tracks/1/imported = false -tracks/1/enabled = true -tracks/1/path = NodePath("CollisionShape3D:position") -tracks/1/interp = 1 -tracks/1/loop_wrap = true -tracks/1/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector3(0, 1, 0)] -} -tracks/2/type = "value" -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/path = NodePath("Camera3D:position") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/keys = { -"times": PackedFloat32Array(0), -"transitions": PackedFloat32Array(1), -"update": 0, -"values": [Vector3(0, 2, 0)] -} - -[sub_resource type="Animation" id="Animation_qhqgy"] -resource_name = "Stand" - -[sub_resource type="AnimationLibrary" id="AnimationLibrary_qlg0r"] -_data = { -&"Crouch": SubResource("Animation_g2els"), -&"RESET": SubResource("Animation_dqkch"), -&"Stand": SubResource("Animation_qhqgy") -} +resource_local_to_scene = true [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g2els"] height = 1.2958984 @@ -118,12 +32,93 @@ properties/1/replication_mode = 1 properties/2/path = NodePath("Camera3D:rotation") properties/2/spawn = true properties/2/replication_mode = 1 -properties/3/path = NodePath(".:crouched") +properties/3/path = NodePath(".:hp") properties/3/spawn = true properties/3/replication_mode = 1 -properties/4/path = NodePath(".:hp") -properties/4/spawn = true -properties/4/replication_mode = 1 + +[sub_resource type="Animation" id="Animation_oprun"] +resource_name = "crouch" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CollisionShape3D:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector3(0, 1, 0), Vector3(0, 0.75, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CollisionShape3D:shape:height") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [2.0, 1.5] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Camera3D:position") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0, 1), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [Vector3(0, 2, 0), Vector3(0, 1.5, 0)] +} + +[sub_resource type="Animation" id="Animation_a8ls1"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("CollisionShape3D:position") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 1, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("CollisionShape3D:shape:height") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [2.0] +} +tracks/2/type = "value" +tracks/2/imported = false +tracks/2/enabled = true +tracks/2/path = NodePath("Camera3D:position") +tracks/2/interp = 1 +tracks/2/loop_wrap = true +tracks/2/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Vector3(0, 2, 0)] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_a8ls1"] +_data = { +&"RESET": SubResource("Animation_a8ls1"), +&"crouch": SubResource("Animation_oprun") +} [node name="Player" type="CharacterBody3D"] collision_layer = 2 @@ -151,9 +146,6 @@ compensation_delay = 0.2 [node name="molikman_hands" parent="Camera3D" instance=ExtResource("4_dqkch")] transform = Transform3D(-1, 0, -8.742278e-08, 0, 1, 0, 8.742278e-08, 0, -1, 0, -1, 0) -[node name="VisibleDisabler" type="Node" parent="Camera3D/molikman_hands"] -script = ExtResource("4_smehm") - [node name="Skeleton3D" parent="Camera3D/molikman_hands/Hands" index="0"] bones/1/position = Vector3(0.16239367, 0.7620353, -0.22555673) bones/1/rotation = Quaternion(-0.013897974, 0.25458142, 0.93291974, 0.25427514) @@ -216,16 +208,14 @@ bones/0/position = Vector3(-0.22279283, 0.7100338, -0.19202478) bones/0/rotation = Quaternion(-0.006717509, 0.6971531, 0.71686494, -0.0060944925) bones/1/position = Vector3(5.970651e-08, 0.06469957, 0.06380712) +[node name="VisibleDisabler" type="Node" parent="Camera3D/molikman_hands"] +script = ExtResource("4_smehm") + [node name="RayCast3D" type="RayCast3D" parent="Camera3D"] target_position = Vector3(0, 0, -1000) collision_mask = 2 script = ExtResource("4_fjrip") -[node name="AnimationPlayer" type="AnimationPlayer" parent="."] -libraries = { -&"": SubResource("AnimationLibrary_qlg0r") -} - [node name="StandArea" type="Area3D" parent="."] collision_layer = 0 @@ -243,6 +233,20 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 +[node name="PanelContainer" type="PanelContainer" parent="HUD"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="VBoxContainer" type="VBoxContainer" parent="HUD/PanelContainer"] +layout_mode = 2 +script = ExtResource("7_oprun") +property_array = Dictionary[NodePath, StringName]({ +NodePath("../../../BodyStateMachine"): &"current_state", +NodePath("../../../WeaponSystem"): &"current_state", +NodePath("../../../AnimationPlayer"): &"current_animation" +}) + [node name="Crosshair" type="Control" parent="HUD"] layout_mode = 1 anchors_preset = 8 @@ -261,6 +265,9 @@ crosses_width = 2.0 crosses_length = 6.0 crosses_offset = 3.0 +[node name="VisibleDisabler" type="Node" parent="HUD"] +script = ExtResource("4_smehm") + [node name="MultiplayerSynchronizer" type="MultiplayerSynchronizer" parent="."] replication_config = SubResource("SceneReplicationConfig_qhqgy") @@ -299,5 +306,10 @@ camera = NodePath("../Camera3D") [node name="Shoot" parent="WeaponSystem/StartingPistol" index="1" node_paths=PackedStringArray("raycast")] raycast = NodePath("../../../Camera3D/RayCast3D") +[node name="AnimationPlayer" type="AnimationPlayer" parent="."] +libraries = { +&"": SubResource("AnimationLibrary_a8ls1") +} + [editable path="Camera3D/molikman_hands"] [editable path="WeaponSystem/StartingPistol"] diff --git a/scripts/debug/property_shower.gd b/scripts/debug/property_shower.gd new file mode 100644 index 0000000..eb06190 --- /dev/null +++ b/scripts/debug/property_shower.gd @@ -0,0 +1,21 @@ +extends VBoxContainer + +@export var property_array: Dictionary[NodePath,StringName] + +func _ready() -> void: + for target in property_array.keys(): + var hbox = HBoxContainer.new() + var name_label = Label.new() + var splitted = property_array[target].split(":") + name_label.text = splitted[len(splitted)-1] + name_label.name = "Name" + var value_label = Label.new() + value_label.name = "Value" + hbox.add_child(name_label,true) + hbox.add_child(value_label,true) + hbox.name = str(target).replace("/","_").replace(".","") + add_child(hbox,true) + +func _process(_delta: float) -> void: + for target in property_array: + get_node(str(target).replace("/","_").replace(".","")+"/Value").text = str(get_node(target).get(property_array[target])) diff --git a/scripts/debug/property_shower.gd.uid b/scripts/debug/property_shower.gd.uid new file mode 100644 index 0000000..684d745 --- /dev/null +++ b/scripts/debug/property_shower.gd.uid @@ -0,0 +1 @@ +uid://7gmgcaxfh8sb diff --git a/scripts/player/states/crouching.gd b/scripts/player/states/crouching.gd index 52eddd3..a6ecf12 100644 --- a/scripts/player/states/crouching.gd +++ b/scripts/player/states/crouching.gd @@ -8,10 +8,10 @@ extends State @export var crouch_time: float = 0.1 func enter() -> void: - animation_player.play("Crouch",-1,1/crouch_time) + animation_player.play("crouch",-1,1/crouch_time) func exit() -> void: - animation_player.play("Crouch",-1,-1/crouch_time,true) + animation_player.play("crouch",-1,-1/crouch_time,true) func physics_update(_delta: float) -> void: if not is_multiplayer_authority(): @@ -33,9 +33,7 @@ func physics_update(_delta: float) -> void: player.velocity.x = move_toward(player.velocity.x, 0, SPEED) player.velocity.z = move_toward(player.velocity.z, 0, SPEED) -func _input(event: InputEvent) -> void: - if not is_multiplayer_authority(): - return +func state_input(event: InputEvent) -> void: if (toggle == true and event.is_action_pressed("plr_crouch")) or (toggle == false and event.is_action_released("plr_crouch")): if stand_up_area.has_overlapping_bodies() == false: transition.emit("Stand") diff --git a/scripts/player/states/standing.gd b/scripts/player/states/standing.gd index 05a81d7..3388958 100644 --- a/scripts/player/states/standing.gd +++ b/scripts/player/states/standing.gd @@ -31,10 +31,7 @@ func physics_update(_delta: float) -> void: player.velocity.x = move_toward(player.velocity.x, 0, SPEED) player.velocity.z = move_toward(player.velocity.z, 0, SPEED) -func _input(event: InputEvent) -> void: - if not is_multiplayer_authority(): - return - +func state_input(event: InputEvent) -> void: if event.is_action_pressed("plr_crouch"): transition.emit("Crouch") diff --git a/scripts/player/states/walk.gd b/scripts/player/states/walk.gd index 5e71712..2cff863 100644 --- a/scripts/player/states/walk.gd +++ b/scripts/player/states/walk.gd @@ -31,9 +31,7 @@ func physics_update(_delta: float) -> void: player.velocity.x = move_toward(player.velocity.x, 0, SPEED) player.velocity.z = move_toward(player.velocity.z, 0, SPEED) -func _input(event: InputEvent) -> void: - if not is_multiplayer_authority(): - return +func state_input(event: InputEvent) -> void: if event.is_action_released("plr_walk"): transition.emit("Stand") diff --git a/scripts/state_machine/machine.gd b/scripts/state_machine/machine.gd index 2ee4bdd..4eca38a 100644 --- a/scripts/state_machine/machine.gd +++ b/scripts/state_machine/machine.gd @@ -9,17 +9,19 @@ func _ready() -> void: for child in get_children(): if child is State: states[child.name] = child - child.transition.connect(on_transition_required.rpc) + child.transition.connect(on_transition_required) else: push_warning("Child of state machine is not state") -@rpc("authority","call_local","reliable") func on_transition_required(to: StringName): + if is_multiplayer_authority() == false: + return if states.has(to) == false: push_warning("Incorrect state request: " + to) return change_state(states[to]) + change_state_to_name.rpc(to) func change_state(to_state: State) -> void: if current_state != null: @@ -27,6 +29,13 @@ func change_state(to_state: State) -> void: current_state = to_state current_state.enter() +@rpc +func change_state_to_name(to_name: StringName): + if current_state != null: + current_state.exit() + current_state = states[to_name] + current_state.enter() + @rpc("authority","call_local","unreliable") func clear_state(): if current_state == null: @@ -39,6 +48,10 @@ func _process(delta: float) -> void: return current_state.update(delta) +func _input(event: InputEvent) -> void: + if current_state != null: + current_state.state_input(event) + func _physics_process(delta: float) -> void: if current_state == null: return diff --git a/scripts/state_machine/state.gd b/scripts/state_machine/state.gd index 4276beb..7e293a5 100644 --- a/scripts/state_machine/state.gd +++ b/scripts/state_machine/state.gd @@ -13,3 +13,5 @@ func update(delta: float) -> void: pass func physics_update(delta: float) -> void: pass +func state_input(event: InputEvent) -> void: + pass diff --git a/scripts/state_machine/substate_machine.gd b/scripts/state_machine/substate_machine.gd index aefb369..26b2384 100644 --- a/scripts/state_machine/substate_machine.gd +++ b/scripts/state_machine/substate_machine.gd @@ -25,3 +25,10 @@ func _process(_delta: float) -> void: func _physics_process(_delta: float) -> void: pass + +func _input(_event: InputEvent) -> void: + pass + +func state_input(event: InputEvent) -> void: + if current_state != null: + current_state.state_input(event) diff --git a/scripts/weapon_system/gun/idle_state.gd b/scripts/weapon_system/gun/idle_state.gd index ffa2a4f..f790d0b 100644 --- a/scripts/weapon_system/gun/idle_state.gd +++ b/scripts/weapon_system/gun/idle_state.gd @@ -8,7 +8,7 @@ func enter() -> void: func exit() -> void: pass -func _input(event: InputEvent) -> void: +func state_input(event: InputEvent) -> void: if not machine.is_multiplayer_authority(): return if event.is_action_pressed("plr_reload"): diff --git a/scripts/weapon_system/weapon_system.gd b/scripts/weapon_system/weapon_system.gd index 0dad3ca..727c295 100644 --- a/scripts/weapon_system/weapon_system.gd +++ b/scripts/weapon_system/weapon_system.gd @@ -84,6 +84,9 @@ func _physics_process(delta: float) -> void: func _input(event: InputEvent) -> void: if is_multiplayer_authority() == false: return + if current_state != null: + current_state.state_input(event) + if event.is_action_pressed("plr_ult"): switch("ultimate") elif event.is_action_pressed("plr_bomb"):