From 085118ddfa048d277f9874f7d5f78e0a189196fa Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 26 Feb 2024 14:53:25 +0000 Subject: [PATCH] Track state entry speed --- content/scenes/player.tscn | 1 + content/scripts/player.gd | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/content/scenes/player.tscn b/content/scenes/player.tscn index 543ab08..818a9b3 100644 --- a/content/scenes/player.tscn +++ b/content/scenes/player.tscn @@ -141,6 +141,7 @@ event = &"Airborne" [node name="Falling" type="Node" parent="StateChart/Root/Airborne"] script = ExtResource("6_8xdrw") +[connection signal="child_state_entered" from="StateChart/Root" to="." method="_on_root_child_state_entered"] [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_physics_processing" from="StateChart/Root/Grounded/Moving/Running" to="." method="_on_running_state_physics_processing"] diff --git a/content/scripts/player.gd b/content/scripts/player.gd index 4d9aaa3..1acf86f 100644 --- a/content/scripts/player.gd +++ b/content/scripts/player.gd @@ -72,6 +72,8 @@ enum MovementType { VERTICAL, LATERAL } #endregion var target_speed := 0.0 +var state_enter_speed := 0.0 + var gravity := 9.8 var _velocity: Vector3 = Vector3() var grounded_prev := false @@ -493,4 +495,8 @@ 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) + +func _on_root_child_state_entered() -> void: + state_enter_speed = target_speed + #endregion