From 5ecbbccf7ebf5371c1e114c3ab8867bb9779564d Mon Sep 17 00:00:00 2001 From: Dustin Date: Sun, 27 Apr 2025 09:37:40 -0700 Subject: [PATCH] Super slippy walk working again! --- lib/classes/movement_state_receiver.gd | 35 ++++++++++++--------- src/actors/players/playerE/states/idle.tres | 2 +- src/actors/players/playerE/states/roll.tres | 2 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index bf18f21..c172492 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -181,6 +181,7 @@ func new_move_actor_as_desired(_delta :float, else: move_direction = resolve_move_direction(calc_inertial_dir, desired_movement_vector) + ## Which direction will acceleration be applied. calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x) ## Direction of inertia not equal to move direction @@ -188,7 +189,10 @@ func new_move_actor_as_desired(_delta :float, if calc_inertial_dir.x: ## And it doesn't apply in the same direction as our movement direction if calc_inertial_dir.x != sign(move_direction.x): - ## flip the direction of acceleration and apply as friction + ## Apply the direction of acceleration and apply as friction + # Friction allows the inertia to trend toward 0 instead of the + # 'To' direction of speed. + ## #calc_friction.x = calc_acceleration.x * -1 calc_friction.x = calc_acceleration.x calc_acceleration.x = 0.0 @@ -230,24 +234,27 @@ func new_move_actor_as_desired(_delta :float, # calc_inertia.x, h_speed.y) elif calc_inertia.x != 0.0: ## We still have inertia but no difference in movement if calc_acceleration.x != 0.0: # We are applying acceleration - if calc_inertia.x > h_speed.x: - calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), - calc_inertia.x, h_speed.x) - else: - calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), - h_speed.x, calc_inertia.x) + ## Move back towards the base speed + calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_acceleration.x * _delta)) +# if calc_inertia.x > h_speed.x: +# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), +# calc_inertia.x, h_speed.x) +# else: +# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), +# h_speed.x, calc_inertia.x) else: ## No longer applying acceleration ## Neutralize the inertia? but how? ## Recalc the acceleration with inertia #var friction :Vector2 calc_friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x) if calc_friction.x != 0.0: ## No dapening acceleration applies - if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down) - calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta), - h_speed.x, calc_inertia.x) - else: ## Inertia lower than base speed (we need to catch up) - calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta), - calc_inertia.x, h_speed.x) + calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, ( calc_friction.x * _delta)) +# if calc_inertia.x > h_speed.x: ## Inertia is higher than the base speed (slow it down) +# calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta), +# h_speed.x, calc_inertia.x) +# else: ## Inertia lower than base speed (we need to catch up) +# calc_inertia.x = clamp( calc_inertia.x + ( calc_friction.x * _delta), +# calc_inertia.x, h_speed.x) else: ## no residual acceleration (friction) applies, kill the momentum calc_inertia.x = 0.0 @@ -284,7 +291,7 @@ func new_move_actor_as_desired(_delta :float, #calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y)) UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + - "H_Speed: {0}, {1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + "\nVelocity_Calc: {0}, {1}".format({"0":"%5.2f" % calc_velocity.x, "1":"%5.2f" % calc_velocity.y}) + "\nInertia_Calc: {0}, {1}".format({"0":"%5.2f" % calc_inertia.x, "1":"%5.2f" % calc_inertia.y}) + "\nVelocity_Real: {0}, {1}".format({"0":"%5.2f" % velocity.x, "1":"%5.2f" % velocity.y}) + diff --git a/src/actors/players/playerE/states/idle.tres b/src/actors/players/playerE/states/idle.tres index 52d8b7f..66454be 100644 --- a/src/actors/players/playerE/states/idle.tres +++ b/src/actors/players/playerE/states/idle.tres @@ -10,7 +10,7 @@ debug_state = false timeout_seconds = 0.0 name = "idle" horizontal_speed = 1.36422e-12 -horizontal_acceleration = 2.0 +horizontal_acceleration = -2.0 horizontal_speed_offset = 0.0 horizontal_speed_offset_acceleration = 0.0 jerk_factor = 0.0 diff --git a/src/actors/players/playerE/states/roll.tres b/src/actors/players/playerE/states/roll.tres index b5dd6d6..bd34015 100644 --- a/src/actors/players/playerE/states/roll.tres +++ b/src/actors/players/playerE/states/roll.tres @@ -12,6 +12,6 @@ name = "roll" horizontal_speed = 150.0 horizontal_acceleration = 1.36422e-12 horizontal_speed_offset = -140.0 -horizontal_speed_offset_acceleration = 30.0 +horizontal_speed_offset_acceleration = 50.0 jerk_factor = 0.0 animation_sequence = [ "roll" ]