Add state debugger UI to playground. Start working on additional states. Implement run acceleration

This commit is contained in:
Jarrod Doyle 2024-02-25 15:22:37 +00:00
parent 050a897cad
commit 2b01dfaeaa
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
3 changed files with 102 additions and 10 deletions

View File

@ -14,7 +14,6 @@ radius = 0.25
[node name="Player" type="StaticBody3D" node_paths=PackedStringArray("head", "body", "camera", "collision_shape", "state_chart")]
script = ExtResource("1_i6r2s")
max_speed = 6
slope_limit = 40.0
step_height = 0.3
snap_to_ground_distance = 0.3
@ -49,7 +48,8 @@ script = ExtResource("5_mmqqh")
initial_state = NodePath("Grounded")
[node name="Grounded" type="Node" parent="StateChart/Root"]
script = ExtResource("6_8xdrw")
script = ExtResource("5_mmqqh")
initial_state = NodePath("Idle")
[node name="On Jump" type="Node" parent="StateChart/Root/Grounded"]
script = ExtResource("7_525mu")
@ -61,13 +61,73 @@ script = ExtResource("7_525mu")
to = NodePath("../../Airborne/Falling")
event = &"Airborne"
[node name="Idle" type="Node" parent="StateChart/Root/Grounded"]
script = ExtResource("5_mmqqh")
initial_state = NodePath("Standling")
[node name="Crouched" type="Node" parent="StateChart/Root/Grounded/Idle"]
script = ExtResource("6_8xdrw")
[node name="On Crouch" type="Node" parent="StateChart/Root/Grounded/Idle/Crouched"]
script = ExtResource("7_525mu")
to = NodePath("../../Standling")
event = &"Crouch"
[node name="On Move" type="Node" parent="StateChart/Root/Grounded/Idle/Crouched"]
script = ExtResource("7_525mu")
to = NodePath("../../../Moving/Crouch Walking")
event = &"Move"
[node name="Standling" type="Node" parent="StateChart/Root/Grounded/Idle"]
script = ExtResource("6_8xdrw")
[node name="On Crouch" type="Node" parent="StateChart/Root/Grounded/Idle/Standling"]
script = ExtResource("7_525mu")
to = NodePath("../../Crouched")
event = &"Crouch"
[node name="On Move" type="Node" parent="StateChart/Root/Grounded/Idle/Standling"]
script = ExtResource("7_525mu")
to = NodePath("../../../Moving/Running")
event = &"Move"
[node name="Moving" type="Node" parent="StateChart/Root/Grounded"]
script = ExtResource("5_mmqqh")
initial_state = NodePath("Running")
[node name="Crouch Walking" type="Node" parent="StateChart/Root/Grounded/Moving"]
script = ExtResource("6_8xdrw")
[node name="On Idle" type="Node" parent="StateChart/Root/Grounded/Moving/Crouch Walking"]
script = ExtResource("7_525mu")
to = NodePath("../../../Idle/Crouched")
event = &"Idle"
[node name="On Crouch" type="Node" parent="StateChart/Root/Grounded/Moving/Crouch Walking"]
script = ExtResource("7_525mu")
to = NodePath("../../Running")
event = &"Crouch"
[node name="Running" type="Node" parent="StateChart/Root/Grounded/Moving"]
script = ExtResource("6_8xdrw")
[node name="On Idle" type="Node" parent="StateChart/Root/Grounded/Moving/Running"]
script = ExtResource("7_525mu")
to = NodePath("../../../Idle/Standling")
event = &"Idle"
[node name="On Crouch" type="Node" parent="StateChart/Root/Grounded/Moving/Running"]
script = ExtResource("7_525mu")
to = NodePath("../../Crouch Walking")
event = &"Crouch"
[node name="Airborne" type="Node" parent="StateChart/Root"]
script = ExtResource("5_mmqqh")
initial_state = NodePath("Jumping")
[node name="On Grounded" type="Node" parent="StateChart/Root/Airborne"]
script = ExtResource("7_525mu")
to = NodePath("../../Grounded")
to = NodePath("../../Grounded/Idle/Standling")
event = &"Grounded"
[node name="Jumping" type="Node" parent="StateChart/Root/Airborne"]
@ -81,6 +141,8 @@ event = &"Airborne"
[node name="Falling" type="Node" parent="StateChart/Root/Airborne"]
script = ExtResource("6_8xdrw")
[connection signal="state_physics_processing" from="StateChart/Root/Grounded" to="." method="_on_grounded_state_physics_processing"]
[connection signal="state_processing" from="StateChart/Root/Grounded/Idle" to="." method="_on_idle_state_processing"]
[connection signal="state_processing" from="StateChart/Root/Grounded/Moving" to="." method="_on_moving_state_processing"]
[connection signal="state_physics_processing" from="StateChart/Root/Grounded/Moving/Running" to="." method="_on_running_state_physics_processing"]
[connection signal="state_physics_processing" from="StateChart/Root/Airborne/Jumping" to="." method="_on_jumping_state_physics_processing"]
[connection signal="state_physics_processing" from="StateChart/Root/Airborne/Falling" to="." method="_on_falling_state_physics_processing"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=274 format=3 uid="uid://dd4qlg15cchu0"]
[gd_scene load_steps=275 format=3 uid="uid://dd4qlg15cchu0"]
[ext_resource type="Script" path="res://addons/qodot/src/nodes/qodot_map.gd" id="1_7j4vn"]
[ext_resource type="PackedScene" uid="uid://ul8o2n823qod" path="res://content/scenes/player.tscn" id="1_qpwbx"]
@ -8,6 +8,7 @@
[ext_resource type="Texture2D" uid="uid://cf6t1ogtfradb" path="res://content/trenchbroom/textures/Prototype/orange9.png" id="5_jv6xk"]
[ext_resource type="Texture2D" uid="uid://dsocqlbvrhy5m" path="res://content/trenchbroom/textures/Prototype/green2.png" id="6_hoyxc"]
[ext_resource type="Texture2D" uid="uid://dgxtptqsev380" path="res://content/trenchbroom/textures/Prototype/white6.png" id="7_xqo7b"]
[ext_resource type="PackedScene" uid="uid://bcwkugn6v3oy7" path="res://addons/godot_state_charts/utilities/state_chart_debugger.tscn" id="9_87np7"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_2t7xo"]
@ -1658,3 +1659,8 @@ shape = SubResource("ConvexPolygonShape3D_0n1bf")
[node name="Player" parent="." instance=ExtResource("1_qpwbx")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -7, 1, 10)
[node name="StateChartDebugger" parent="." instance=ExtResource("9_87np7")]
offset_right = -772.0
offset_bottom = -415.0
initial_node_to_watch = NodePath("../Player")

View File

@ -71,6 +71,7 @@ enum MovementType { VERTICAL, LATERAL }
#endregion
var target_speed := 0.0
var gravity := 9.8
var _velocity: Vector3 = Vector3()
var grounded: bool = false
@ -427,9 +428,14 @@ func _vert(value: Vector3) -> Vector3:
return Vector3(0, value.y, 0)
func _on_grounded_state_physics_processing(delta: float) -> void:
var move_speed := run_speed if Input.is_action_pressed("cc_sprint") else crouch_speed
var target_velocity_h := get_move_dir() * move_speed
func _on_running_state_physics_processing(delta: float) -> void:
if target_speed < run_speed:
target_speed += (run_speed / run_acceleration_time) * delta
else:
# TODO Decelerate
target_speed = run_speed
var target_velocity_h := get_move_dir() * target_speed
var target_velocity_v := -gravity * delta
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
move(target_velocity, delta)
@ -441,7 +447,7 @@ func _on_grounded_state_physics_processing(delta: float) -> void:
func _on_falling_state_physics_processing(delta: float) -> void:
var move_speed := run_speed if Input.is_action_pressed("cc_sprint") else crouch_speed
var move_speed := run_speed
var target_velocity_h := get_move_dir() * move_speed
var target_velocity_v := _velocity.y - gravity * delta
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
@ -452,10 +458,28 @@ func _on_falling_state_physics_processing(delta: float) -> void:
func _on_jumping_state_physics_processing(delta: float) -> void:
var move_speed := run_speed if Input.is_action_pressed("cc_sprint") else crouch_speed
var move_speed := run_speed
var target_velocity_h := get_move_dir() * move_speed
var target_velocity_v := jump_speed
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
move(target_velocity, delta)
state_chart.send_event("Airborne")
# TODO Rename sprint to crouch
func _on_idle_state_processing(_delta: float) -> void:
# !HACK - No deceleration. Just reset the target speed for now
target_speed = 0.0
if get_move_dir() != Vector2.ZERO:
state_chart.send_event("Move")
if Input.is_action_just_pressed("cc_sprint"):
state_chart.send_event("Crouch")
func _on_moving_state_processing(_delta: float) -> void:
if get_move_dir() == Vector2.ZERO:
state_chart.send_event("Idle")
if Input.is_action_just_pressed("cc_sprint"):
state_chart.send_event("Crouch")