Close #1: Basic running deceleration
This commit is contained in:
parent
085118ddfa
commit
0c1ded340a
|
@ -446,6 +446,9 @@ func _get_move_dir() -> Vector2:
|
||||||
|
|
||||||
|
|
||||||
func _on_root_state_processing(_delta: float) -> void:
|
func _on_root_state_processing(_delta: float) -> void:
|
||||||
|
# !HACK - Printing this here for tracking
|
||||||
|
print(target_speed)
|
||||||
|
|
||||||
if _get_move_dir() == Vector2.ZERO:
|
if _get_move_dir() == Vector2.ZERO:
|
||||||
state_chart.send_event("Idle")
|
state_chart.send_event("Idle")
|
||||||
else:
|
else:
|
||||||
|
@ -468,11 +471,13 @@ func _on_idle_state_processing(_delta: float) -> void:
|
||||||
|
|
||||||
|
|
||||||
func _on_running_state_physics_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 += (run_speed / run_acceleration_time) * delta
|
||||||
|
target_speed = minf(target_speed, run_speed)
|
||||||
else:
|
else:
|
||||||
# TODO Decelerate
|
var decel_rate := (state_enter_speed - run_speed) / run_deceleration_time
|
||||||
target_speed = run_speed
|
target_speed -= decel_rate * delta
|
||||||
|
target_speed = maxf(target_speed, run_speed)
|
||||||
|
|
||||||
var target_velocity_h := _get_move_dir() * target_speed
|
var target_velocity_h := _get_move_dir() * target_speed
|
||||||
var target_velocity_v := -gravity * delta
|
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:
|
func _on_jumping_state_physics_processing(delta: float) -> void:
|
||||||
var move_speed := run_speed
|
# !HACK - We're setting this to test run deceleration
|
||||||
var target_velocity_h := _get_move_dir() * move_speed
|
target_speed = run_speed + 2.0
|
||||||
|
var target_velocity_h := _get_move_dir() * target_speed
|
||||||
var target_velocity_v := jump_speed
|
var target_velocity_v := jump_speed
|
||||||
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
|
var target_velocity := Vector3(target_velocity_h.x, target_velocity_v, target_velocity_h.y)
|
||||||
move(target_velocity, delta)
|
move(target_velocity, delta)
|
||||||
|
|
Loading…
Reference in New Issue