From d4077cff43bff6c100f5fb8f6e018bdcca1745f3 Mon Sep 17 00:00:00 2001 From: Dustin Date: Sun, 27 Apr 2025 08:24:35 -0700 Subject: [PATCH] Swithing to move_toward based acceleration. All accel would have to be positive. --- lib/classes/movement_state_receiver.gd | 49 ++++++++++++++++----- src/actors/players/playerE/states/idle.tres | 2 +- src/actors/players/playerE/states/move.tres | 6 +-- src/actors/players/playerE/states/roll.tres | 6 +-- 4 files changed, 45 insertions(+), 18 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index 7d74eb3..bf18f21 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -184,10 +184,18 @@ func new_move_actor_as_desired(_delta :float, calc_acceleration.x = resolve_h_acceleration(movement_params, h_speed, move_direction.x) ## Direction of inertia not equal to move direction - if calc_inertial_dir.x: + ## If inertia is applying in a direction + 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 - calc_acceleration.x *= -1 + ## flip the direction of acceleration and apply as friction + #calc_friction.x = calc_acceleration.x * -1 + calc_friction.x = calc_acceleration.x + calc_acceleration.x = 0.0 + + + + ## We are always moving from h_speed.x towards y at a given rate ## if we have a difference of speed if h_speed.x != h_speed.y: @@ -195,8 +203,18 @@ func new_move_actor_as_desired(_delta :float, ## Clamp inertia to in between speed. # Problem is that we can suddenly gain or lose inertia. ## - calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), - h_speed.x , h_speed.y) +# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), +# h_speed.x , h_speed.y) + ## If there is currently no inertia apply the base h_speed + if calc_inertia.x == 0.0: + calc_inertia.x = h_speed.x + ## Apply acceleration + calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta)) + ## Apply friction + calc_inertia.x = move_toward(calc_inertia.x, 0, (calc_friction.x * _delta)) +# calc_inertia.x = clamp( calc_inertia.x + (calc_friction.x * _delta), +# 0 , h_speed.y) + ## Disable this for now hopefully inertial acceleration flip removes this ## Update: it mostly did. Going to keep this here for a while though. @@ -294,13 +312,20 @@ func resolve_h_speed(_params :Dictionary) -> Vector2: if _params["_base_h_move_speed_modifier"] != 0: var speed_differance = base_speed + _params["_base_h_move_speed_modifier"] - #return(Vector2(base_speed, speed_differance)) +# if sign(_params["_base_h_move_speed_modifier"]) == -1: +# return Vector2(speed_differance, base_speed) +# else: +# return Vector2(base_speed, speed_differance) + + + return(Vector2(base_speed, speed_differance)) ## We start at a slower base speed and move upward - if speed_differance > base_speed: - return(Vector2(base_speed, speed_differance)) - else: - ## We start at a higher speed and move downward to base - return(Vector2(speed_differance, base_speed )) + ## Disabled because flipping accel direction may make more sense. +# if speed_differance > base_speed: +# return(Vector2(base_speed, speed_differance)) +# else: +# ## We start at a higher speed and move downward to base +# return(Vector2(speed_differance, base_speed )) # if inertia: # return Vector2(0,inertia) return Vector2(base_speed,base_speed) @@ -318,6 +343,8 @@ func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_directio ## Well this didn't work #_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] + #return _acceleration + if _speed.x < _speed.y: return _acceleration elif _speed.x > _speed.y: diff --git a/src/actors/players/playerE/states/idle.tres b/src/actors/players/playerE/states/idle.tres index e9e77fe..52d8b7f 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 = 0.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/move.tres b/src/actors/players/playerE/states/move.tres index a498f35..d380a52 100644 --- a/src/actors/players/playerE/states/move.tres +++ b/src/actors/players/playerE/states/move.tres @@ -9,9 +9,9 @@ script = ExtResource( 1 ) debug_state = false timeout_seconds = 0.0 name = "move" -horizontal_speed = 90.0 -horizontal_acceleration = 180.0 -horizontal_speed_offset = -80.0 +horizontal_speed = 10.0 +horizontal_acceleration = 20.0 +horizontal_speed_offset = 80.0 horizontal_speed_offset_acceleration = 0.0 jerk_factor = 0.0 animation_sequence = [ "run" ] diff --git a/src/actors/players/playerE/states/roll.tres b/src/actors/players/playerE/states/roll.tres index a3e3d9a..b5dd6d6 100644 --- a/src/actors/players/playerE/states/roll.tres +++ b/src/actors/players/playerE/states/roll.tres @@ -9,9 +9,9 @@ script = ExtResource( 1 ) debug_state = false timeout_seconds = 0.0 name = "roll" -horizontal_speed = 10.0 +horizontal_speed = 150.0 horizontal_acceleration = 1.36422e-12 -horizontal_speed_offset = 140.0 -horizontal_speed_offset_acceleration = 150.0 +horizontal_speed_offset = -140.0 +horizontal_speed_offset_acceleration = 30.0 jerk_factor = 0.0 animation_sequence = [ "roll" ]