From 0c1ded340a2c63ca204bfe58faadc194a4755a05 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Mon, 26 Feb 2024 14:54:03 +0000 Subject: [PATCH] Close #1: Basic running deceleration --- content/scripts/player.gd | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/content/scripts/player.gd b/content/scripts/player.gd index 1acf86f..b0b0920 100644 --- a/content/scripts/player.gd +++ b/content/scripts/player.gd @@ -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)