Move the rest of event sending into root state

This commit is contained in:
Jarrod Doyle 2024-02-25 16:59:20 +00:00
parent bcff3d172e
commit eda51bcb50
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 7 additions and 6 deletions

View File

@ -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