refactor to state machine

This commit is contained in:
2025-02-02 01:08:44 +09:00
parent c8c5c08b4d
commit be682b2813
18 changed files with 379 additions and 121 deletions
+2 -3
View File
@@ -87,7 +87,6 @@ mesh = SubResource("BoxMesh_thq07")
[node name="Ceiling" type="StaticBody3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 10, 0)
visible = false
[node name="CollisionShape3D" type="CollisionShape3D" parent="Ceiling"]
shape = SubResource("BoxShape3D_xn166")
@@ -151,7 +150,7 @@ omni_attenuation = 1.5
[node name="SecondFloorLight" type="OmniLight3D" parent="Lights"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 9, 0)
visible = false
light_energy = 0.3
light_energy = 6.0
shadow_enabled = true
omni_range = 40.0
omni_attenuation = 1.5
+9 -8
View File
@@ -24,24 +24,25 @@ environment = SubResource("Environment_2c67a")
[node name="MultiplayerSpawner" type="MultiplayerSpawner" parent="."]
_spawnable_scenes = PackedStringArray("res://scenes/runner.tscn")
spawn_path = NodePath("../RunnersNode")
spawn_path = NodePath("../Runners")
[node name="GroundStaticBody3D" type="StaticBody3D" parent="."]
[node name="Ground" type="StaticBody3D" parent="."]
[node name="GroundCollisionShape3D" type="CollisionShape3D" parent="GroundStaticBody3D"]
[node name="GroundCollider" type="CollisionShape3D" parent="Ground"]
shape = SubResource("WorldBoundaryShape3D_1l61b")
[node name="GroundMeshInstance3D" type="MeshInstance3D" parent="GroundStaticBody3D"]
[node name="GroundMesh" type="MeshInstance3D" parent="Ground"]
mesh = ExtResource("1_7j0qh")
surface_material_override/0 = ExtResource("2_f8uto")
[node name="House" parent="." instance=ExtResource("4_38bom")]
[node name="RunnersNode" type="Node3D" parent="."]
[node name="Runners" type="Node3D" parent="."]
unique_name_in_owner = true
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="StatsOverlay" type="CanvasLayer" parent="."]
[node name="Control" type="Control" parent="CanvasLayer"]
[node name="StatsContainer" type="Control" parent="StatsOverlay"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@@ -49,7 +50,7 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/Control"]
[node name="StatsLabel" type="RichTextLabel" parent="StatsOverlay/StatsContainer"]
unique_name_in_owner = true
layout_mode = 0
offset_right = 200.0
+9 -9
View File
@@ -11,7 +11,7 @@ grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ivhyr")
[node name="MainMenuPanel" type="Panel" parent="."]
[node name="Panel" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
@@ -19,7 +19,7 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="ColorRect" type="ColorRect" parent="MainMenuPanel"]
[node name="Background" type="ColorRect" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
@@ -28,7 +28,7 @@ grow_horizontal = 2
grow_vertical = 2
color = Color(0.156863, 0.156863, 0.305882, 1)
[node name="MainMenuCenterContainer" type="CenterContainer" parent="MainMenuPanel"]
[node name="Center" type="CenterContainer" parent="Panel"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
@@ -36,10 +36,10 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="MainMenuVBoxContainer" type="VBoxContainer" parent="MainMenuPanel/MainMenuCenterContainer"]
[node name="VerticalMenu" type="VBoxContainer" parent="Panel/Center"]
layout_mode = 2
[node name="IpAddressRichTextLabel" type="RichTextLabel" parent="MainMenuPanel/MainMenuCenterContainer/MainMenuVBoxContainer"]
[node name="IpLabel" type="RichTextLabel" parent="Panel/Center/VerticalMenu"]
custom_minimum_size = Vector2(0, 25)
layout_mode = 2
size_flags_vertical = 4
@@ -47,21 +47,21 @@ bbcode_enabled = true
text = "[center]Server Address[/center]"
scroll_active = false
[node name="IpAddressTextEdit" type="TextEdit" parent="MainMenuPanel/MainMenuCenterContainer/MainMenuVBoxContainer"]
[node name="IpTextBox" type="TextEdit" parent="Panel/Center/VerticalMenu"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 40)
layout_mode = 2
size_flags_vertical = 4
placeholder_text = "localhost (default)"
[node name="JoinButtonSpacer" type="Control" parent="MainMenuPanel/MainMenuCenterContainer/MainMenuVBoxContainer"]
[node name="JoinButtonSpacer" type="Control" parent="Panel/Center/VerticalMenu"]
custom_minimum_size = Vector2(0, 15)
layout_mode = 2
[node name="JoinButton" type="Button" parent="MainMenuPanel/MainMenuCenterContainer/MainMenuVBoxContainer"]
[node name="JoinButton" type="Button" parent="Panel/Center/VerticalMenu"]
custom_minimum_size = Vector2(200, 40)
layout_mode = 2
text = "Join"
text_overrun_behavior = 3
[connection signal="pressed" from="MainMenuPanel/MainMenuCenterContainer/MainMenuVBoxContainer/JoinButton" to="." method="_on_join_button_pressed"]
[connection signal="pressed" from="Panel/Center/VerticalMenu/JoinButton" to="." method="_on_join_button_pressed"]
+113
View File
@@ -0,0 +1,113 @@
[gd_scene load_steps=16 format=3 uid="uid://8esyynmieyog"]
[ext_resource type="Script" path="res://scripts/runner.gd" id="1_d63rt"]
[ext_resource type="Script" path="res://scripts/runner_input.gd" id="2_xmliy"]
[ext_resource type="Material" uid="uid://ccrb46njti2ke" path="res://materials/runner.tres" id="3_6c0ro"]
[ext_resource type="Script" path="res://scripts/state_machine.gd" id="4_40cmc"]
[ext_resource type="Script" path="res://scripts/states/idle.gd" id="5_hq6tn"]
[ext_resource type="Script" path="res://scripts/states/move.gd" id="6_1teax"]
[ext_resource type="Script" path="res://scripts/states/fall.gd" id="7_jfat4"]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ukf45"]
properties/0/path = NodePath(".:player_id")
properties/0/spawn = true
properties/0/replication_mode = 2
properties/1/path = NodePath(".:server_position")
properties/1/spawn = true
properties/1/replication_mode = 2
properties/2/path = NodePath(".:server_rotation")
properties/2/spawn = true
properties/2/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_1agtp"]
properties/0/path = NodePath("RunnerInput:move_direction")
properties/0/spawn = true
properties/0/replication_mode = 2
[sub_resource type="SphereShape3D" id="SphereShape3D_wsx1k"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_j6tb3"]
radius = 0.3
height = 1.8
[sub_resource type="CapsuleMesh" id="CapsuleMesh_di3a0"]
radius = 0.3
height = 1.8
[sub_resource type="PrismMesh" id="PrismMesh_fcj1v"]
[sub_resource type="SphereMesh" id="SphereMesh_tudvv"]
[sub_resource type="SphereMesh" id="SphereMesh_1gltg"]
[node name="Runner" type="CharacterBody3D" node_paths=PackedStringArray("state_machine")]
script = ExtResource("1_d63rt")
state_machine = NodePath("StateMachine")
[node name="RunnerSync" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_ukf45")
[node name="RunnerInput" type="MultiplayerSynchronizer" parent="."]
unique_name_in_owner = true
replication_config = SubResource("SceneReplicationConfig_1agtp")
script = ExtResource("2_xmliy")
[node name="Camera" type="Camera3D" parent="."]
unique_name_in_owner = true
[node name="CameraPivot" type="Node3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
[node name="CameraSpringArm" type="SpringArm3D" parent="CameraPivot"]
shape = SubResource("SphereShape3D_wsx1k")
spring_length = 3.5
[node name="CameraTarget" type="Node3D" parent="CameraPivot/CameraSpringArm"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
[node name="Collider" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("CapsuleShape3D_j6tb3")
[node name="Skin" type="Node3D" parent="."]
unique_name_in_owner = true
[node name="MainBody" type="MeshInstance3D" parent="Skin"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
mesh = SubResource("CapsuleMesh_di3a0")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("3_6c0ro")
[node name="Beak" type="MeshInstance3D" parent="Skin/MainBody"]
transform = Transform3D(0.35, 0, 0, 0, -1.09278e-08, 0.1, 0, -0.25, -4.37114e-09, 0, 0.65, -0.3)
visible = false
mesh = SubResource("PrismMesh_fcj1v")
surface_material_override/0 = ExtResource("3_6c0ro")
[node name="RightEye" type="MeshInstance3D" parent="Skin/MainBody"]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0.1, 0.6, -0.25)
mesh = SubResource("SphereMesh_tudvv")
[node name="LeftEye" type="MeshInstance3D" parent="Skin/MainBody"]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, -0.1, 0.6, -0.25)
mesh = SubResource("SphereMesh_1gltg")
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("current_state")]
script = ExtResource("4_40cmc")
current_state = NodePath("Idle")
[node name="Idle" type="Node" parent="StateMachine" node_paths=PackedStringArray("move_state")]
script = ExtResource("5_hq6tn")
move_state = NodePath("../Move")
[node name="Move" type="Node" parent="StateMachine" node_paths=PackedStringArray("idle_state", "fall_state")]
script = ExtResource("6_1teax")
idle_state = NodePath("../Idle")
fall_state = NodePath("../Fall")
[node name="Fall" type="Node" parent="StateMachine" node_paths=PackedStringArray("move_state", "idle_state")]
script = ExtResource("7_jfat4")
move_state = NodePath("../Move")
idle_state = NodePath("../Idle")
+50 -18
View File
@@ -1,10 +1,13 @@
[gd_scene load_steps=12 format=3 uid="uid://8esyynmieyog"]
[gd_scene load_steps=17 format=3 uid="uid://8esyynmieyog"]
[ext_resource type="Script" path="res://scripts/runner.gd" id="1_d63rt"]
[ext_resource type="Script" path="res://scripts/runner_input.gd" id="2_xmliy"]
[ext_resource type="Script" path="res://scripts/multiplayer/input.gd" id="2_xmliy"]
[ext_resource type="Material" uid="uid://ccrb46njti2ke" path="res://materials/runner.tres" id="3_6c0ro"]
[ext_resource type="Script" path="res://scripts/state_machine.gd" id="4_40cmc"]
[ext_resource type="Script" path="res://scripts/states/state_machine.gd" id="4_40cmc"]
[ext_resource type="Script" path="res://scripts/states/idle.gd" id="5_hq6tn"]
[ext_resource type="Script" path="res://scripts/states/run.gd" id="6_1teax"]
[ext_resource type="Script" path="res://scripts/states/fall.gd" id="7_jfat4"]
[ext_resource type="Script" path="res://scripts/states/walk.gd" id="8_phh70"]
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_ukf45"]
properties/0/path = NodePath(".:player_id")
@@ -18,9 +21,12 @@ properties/2/spawn = true
properties/2/replication_mode = 2
[sub_resource type="SceneReplicationConfig" id="SceneReplicationConfig_1agtp"]
properties/0/path = NodePath("RunnerInput:move_direction")
properties/0/path = NodePath("Input:direction")
properties/0/spawn = true
properties/0/replication_mode = 2
properties/1/path = NodePath("Input:walking")
properties/1/spawn = true
properties/1/replication_mode = 2
[sub_resource type="SphereShape3D" id="SphereShape3D_wsx1k"]
@@ -34,52 +40,78 @@ height = 1.8
[sub_resource type="PrismMesh" id="PrismMesh_fcj1v"]
[node name="Runner" type="CharacterBody3D"]
script = ExtResource("1_d63rt")
[sub_resource type="SphereMesh" id="SphereMesh_tudvv"]
[node name="RunnerSync" type="MultiplayerSynchronizer" parent="."]
[sub_resource type="SphereMesh" id="SphereMesh_1gltg"]
[node name="Runner" type="CharacterBody3D" node_paths=PackedStringArray("state_machine")]
script = ExtResource("1_d63rt")
state_machine = NodePath("StateMachine")
[node name="Sync" type="MultiplayerSynchronizer" parent="."]
replication_config = SubResource("SceneReplicationConfig_ukf45")
[node name="RunnerInput" type="MultiplayerSynchronizer" parent="."]
[node name="Input" type="MultiplayerSynchronizer" parent="."]
unique_name_in_owner = true
replication_config = SubResource("SceneReplicationConfig_1agtp")
script = ExtResource("2_xmliy")
[node name="RunnerCamera" type="Camera3D" parent="."]
[node name="Camera" type="Camera3D" parent="."]
unique_name_in_owner = true
[node name="CameraPivot" type="Node3D" parent="."]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
[node name="RunnerCameraSpringArm3D" type="SpringArm3D" parent="CameraPivot"]
[node name="CameraSpringArm" type="SpringArm3D" parent="CameraPivot"]
shape = SubResource("SphereShape3D_wsx1k")
spring_length = 3.5
[node name="RunnerCameraTarget" type="Node3D" parent="CameraPivot/RunnerCameraSpringArm3D"]
[node name="CameraTarget" type="Node3D" parent="CameraPivot/CameraSpringArm"]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 0)
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
[node name="Collider" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
shape = SubResource("CapsuleShape3D_j6tb3")
[node name="RunnerSkin" type="Node3D" parent="."]
[node name="Skin" type="Node3D" parent="."]
unique_name_in_owner = true
[node name="MeshInstance3D" type="MeshInstance3D" parent="RunnerSkin"]
[node name="MainBody" type="MeshInstance3D" parent="Skin"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
mesh = SubResource("CapsuleMesh_di3a0")
skeleton = NodePath("../..")
surface_material_override/0 = ExtResource("3_6c0ro")
[node name="MeshInstance3D" type="MeshInstance3D" parent="RunnerSkin/MeshInstance3D"]
transform = Transform3D(0.35, 0, 0, 0, -1.09278e-08, 0.1, 0, -0.25, -4.37114e-09, 0, 0.65, -0.3)
[node name="Beak" type="MeshInstance3D" parent="Skin/MainBody"]
transform = Transform3D(0.35, 0, 0, 0, -0.105655, 0.0906308, 0, -0.226577, -0.0422618, 0, 0.45, -0.3)
mesh = SubResource("PrismMesh_fcj1v")
surface_material_override/0 = ExtResource("3_6c0ro")
[node name="StateMachine" type="Node" parent="."]
[node name="RightEye" type="MeshInstance3D" parent="Skin/MainBody"]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, 0.1, 0.6, -0.25)
mesh = SubResource("SphereMesh_tudvv")
[node name="LeftEye" type="MeshInstance3D" parent="Skin/MainBody"]
transform = Transform3D(0.1, 0, 0, 0, 0.1, 0, 0, 0, 0.1, -0.1, 0.6, -0.25)
mesh = SubResource("SphereMesh_1gltg")
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("current_state")]
script = ExtResource("4_40cmc")
current_state = NodePath("Idle")
[node name="Idle" type="Node" parent="StateMachine"]
unique_name_in_owner = true
script = ExtResource("5_hq6tn")
[node name="Run" type="Node" parent="StateMachine"]
unique_name_in_owner = true
script = ExtResource("6_1teax")
[node name="Fall" type="Node" parent="StateMachine"]
unique_name_in_owner = true
script = ExtResource("7_jfat4")
[node name="Walk" type="Node" parent="StateMachine"]
unique_name_in_owner = true
script = ExtResource("8_phh70")