From eda51bcb50b0e62c00f0069a8e06bbe2f034b236 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 25 Feb 2024 16:59:20 +0000 Subject: [PATCH] Move the rest of event sending into root state --- content/scripts/player.gd | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/content/scripts/player.gd b/content/scripts/player.gd index 3a8335c..1c4257d 100644 --- a/content/scripts/player.gd +++ b/content/scripts/player.gd @@ -74,7 +74,8 @@ enum MovementType { VERTICAL, LATERAL } var target_speed := 0.0 var gravity := 9.8 var _velocity: Vector3 = Vector3() -var grounded: bool = false +var grounded_prev := false +var grounded := true var ground_normal: Vector3 var steep_slope_normals: Array[Vector3] = [] var total_stepped_height: float = 0 @@ -448,9 +449,6 @@ func _on_falling_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 grounded: - state_chart.send_event("Grounded") - func _on_jumping_state_physics_processing(delta: float) -> void: var move_speed := run_speed @@ -475,5 +473,8 @@ func _on_root_state_processing(_delta: float) -> void: state_chart.send_event("Crouch") if Input.is_action_just_pressed("cc_jump"): state_chart.send_event("Jump") - if !grounded: - state_chart.send_event("Airborne") + + if grounded != grounded_prev: + var event := "Grounded" if grounded else "Airborne" + state_chart.send_event(event) + grounded_prev = grounded