Close #1: Basic running deceleration

This commit is contained in:
Jarrod Doyle 2024-02-26 14:54:03 +00:00
parent 085118ddfa
commit 0c1ded340a
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 11 additions and 5 deletions

View File

@ -446,6 +446,9 @@ func _get_move_dir() -> Vector2:
func _on_root_state_processing(_delta: float) -> void:
# !HACK - Printing this here for tracking
print(target_speed)
if _get_move_dir() == Vector2.ZERO:
state_chart.send_event("Idle")
else:
@ -468,11 +471,13 @@ func _on_idle_state_processing(_delta: float) -> void:
func _on_running_state_physics_processing(delta: float) -> void:
if target_speed < run_speed:
if state_enter_speed < run_speed:
target_speed += (run_speed / run_acceleration_time) * delta
target_speed = minf(target_speed, run_speed)
else:
# TODO Decelerate
target_speed = run_speed
var decel_rate := (state_enter_speed - run_speed) / run_deceleration_time
target_speed -= decel_rate * delta
target_speed = maxf(target_speed, run_speed)
var target_velocity_h := _get_move_dir() * target_speed
var target_velocity_v := -gravity * delta
@ -489,8 +494,9 @@ func _on_falling_state_physics_processing(delta: float) -> void:
func _on_jumping_state_physics_processing(delta: float) -> void:
var move_speed := run_speed
var target_velocity_h := _get_move_dir() * move_speed
# !HACK - We're setting this to test run deceleration
target_speed = run_speed + 2.0
var target_velocity_h := _get_move_dir() * target_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)