From bcff3d172ef2efed2d9727a3c2df9ae4818b0376 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 25 Feb 2024 16:53:35 +0000 Subject: [PATCH] Moved some event handling to the root state --- content/scenes/player.tscn | 2 +- content/scripts/player.gd | 22 +++++++--------------- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/content/scenes/player.tscn b/content/scenes/player.tscn index 78fe334..543ab08 100644 --- a/content/scenes/player.tscn +++ b/content/scenes/player.tscn @@ -141,8 +141,8 @@ event = &"Airborne" [node name="Falling" type="Node" parent="StateChart/Root/Airborne"] script = ExtResource("6_8xdrw") +[connection signal="state_processing" from="StateChart/Root" to="." method="_on_root_state_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"] diff --git a/content/scripts/player.gd b/content/scripts/player.gd index 3fa7ff1..3a8335c 100644 --- a/content/scripts/player.gd +++ b/content/scripts/player.gd @@ -440,11 +440,6 @@ func _on_running_state_physics_processing(delta: float) -> void: var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y) move(target_velocity, delta) - if Input.is_action_just_pressed("cc_jump"): - state_chart.send_event("Jump") - elif !grounded: - state_chart.send_event("Airborne") - func _on_falling_state_physics_processing(delta: float) -> void: var move_speed := run_speed @@ -464,24 +459,21 @@ func _on_jumping_state_physics_processing(delta: float) -> void: 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: + +func _on_root_state_processing(_delta: float) -> void: + if get_move_dir() == Vector2.ZERO: + state_chart.send_event("Idle") + else: state_chart.send_event("Move") if Input.is_action_just_pressed("cc_sprint"): state_chart.send_event("Crouch") if Input.is_action_just_pressed("cc_jump"): state_chart.send_event("Jump") - - -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") + if !grounded: + state_chart.send_event("Airborne")