From dc6802cbce481b8ce17773a8b48e7742db294c86 Mon Sep 17 00:00:00 2001 From: Dustin Date: Sat, 26 Apr 2025 15:12:54 -0700 Subject: [PATCH] Somehow broke the last movement. --- lib/classes/movement_state_receiver.gd | 76 ++++++++++++++++---------- 1 file changed, 48 insertions(+), 28 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index f823e2b..0e74888 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -162,7 +162,7 @@ func new_move_actor_as_desired(_delta :float, var calc_acceleration = Vector2.ZERO #var calc_inertia = Vector2.ZERO #var calc_inertia = inertia - + var friction :Vector2 = Vector2.ZERO ## Inertia only applies if there is a difference between the # base move speed and a derived move speed. This makes it so all you @@ -182,17 +182,28 @@ 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 calc_inertial_dir.x != sign(move_direction.x): + ## flip the direction of acceleration + calc_acceleration.x *= -1 + ## if we have a difference of speed if h_speed.x != h_speed.y: debug_speed_tracker = h_speed - if calc_inertia.x == 0.0: - #calc_inertia.x = lerp( h_speed.x , h_speed.y, calc_acceleration.x * _delta) - calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), - h_speed.x , h_speed.y) - else: - #calc_inertia.x = lerp( calc_inertia.x, h_speed.y, calc_acceleration.x * _delta) - calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), - calc_inertia.x, h_speed.y) + ## Aceleration needs to be the sign of the direction we're moving in + calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), + h_speed.x , h_speed.y) + + ## Disable this for now hopefully inertial acceleration flip removes this +# if calc_inertia.x == 0.0: +# #calc_inertia.x = lerp( h_speed.x , h_speed.y, calc_acceleration.x * _delta) +# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), +# h_speed.x , h_speed.y) +# else: +# #calc_inertia.x = lerp( calc_inertia.x, h_speed.y, calc_acceleration.x * _delta) +# calc_inertia.x = clamp( calc_inertia.x + ( calc_acceleration.x * _delta), +# calc_inertia.x, h_speed.y) elif calc_inertia.x != 0.0: ## We still have inertia if calc_acceleration.x != 0.0: # We are applying acceleration if calc_inertia.x > h_speed.x: @@ -204,7 +215,7 @@ func new_move_actor_as_desired(_delta :float, else: ## No longer applying acceleration ## Neutralize the inertia? but how? ## Recalc the acceleration with inertia - var friction :Vector2 + #var friction :Vector2 friction.x = resolve_h_acceleration(movement_params,Vector2(calc_inertia.x, h_speed.x), move_direction.x) if 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) @@ -229,12 +240,21 @@ func new_move_actor_as_desired(_delta :float, ## Another idea, just return the calculated velocity in PPS ## For now, y component of velocity is just gravity - calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y + #calc_velocity.y = movement_params["_gravity"] * Vector2.DOWN.y + + calc_inertia.y = velocity.y + calc_inertia.y += movement_params["_gravity"] * _delta + calc_velocity.y = calc_inertia.y + ## calc x component of felicty + ## Can't do it this way when we have initia + #calc_velocity.x = calc_inertia.x * move_direction.x + if calc_inertial_dir.x != 0: calc_velocity.x = calc_inertia.x * calc_inertial_dir.x else: calc_velocity.x = calc_inertia.x * move_direction.x + calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y)) UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + @@ -242,7 +262,7 @@ func new_move_actor_as_desired(_delta :float, "\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}) + - "\nAccel: {0}, {1}".format({"0":"%5.2f" % acceleration.x, "1":"%5.2f" % acceleration.y}) + + "\nFriction: {0}, {1}".format({"0":"%5.2f" % friction.x, "1":"%5.2f" % friction.y}) + "\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) + #"\nLength: " + str(velocity.length()) + @@ -279,19 +299,20 @@ func resolve_h_speed(_params :Dictionary) -> Vector2: func resolve_h_acceleration(_params :Dictionary, _speed :Vector2, _move_direction :float) -> float: ## TODO: Adjust for jerk, determine if we're currently experiencing accel ## if a speed difference applies - var _acceleration :float = 0.0 + var _acceleration :float = 0.0 if _params["_base_h_move_speed_modifier"] != 0: _acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] else: _acceleration = _params["_base_h_move_acceleration"] - + + #_acceleration *= sign(_move_direction) ## Well this didn't work #_acceleration = _params["_base_h_move_acceleration"] + _params["_base_h_move_modifier_move_acceleration"] if _speed.x < _speed.y: - return _acceleration + return _acceleration elif _speed.x > _speed.y: - return _acceleration * -1 + return _acceleration * -1 return 0.0 func resolve_move_direction(_momentum :Vector2, @@ -402,28 +423,27 @@ func move_actor_as_desired( x_move_direction_override: float = 0): acceleration.x = _move_modifier_move_acceleration + _move_acceleration # If we're no longer tryingg to move int the direction of our movement and momentum. - if sign(current_x_velocity) != sign(desired_movement_vector.x) and momentum.x != 0: + if (sign(current_x_velocity) != sign(desired_movement_vector.x) and momentum.x != 0): if sign(_move_speed_modifier) == -1 : # decreased speed modifier - # Maybe we can compare the direction of the acceleration # The direction of the acceleration should usually be positive at this point. # when the modifier is negative. if sign(move_direction) == sign(current_x_velocity): if sign(acceleration.x) == sign(momentum.x): - print("Whoh Woah") - # Flip the direction of the acceleration acceleration.x *= -1 + # print("Whoh Woah") + # Flip the direction of the acceleration if (sign(desired_movement_vector.x) == -1 and sign(current_x_velocity) == 1) or (sign(desired_movement_vector.x) == -1 and sign(current_x_velocity) == -1): - print("be more opposite") -# if sign(_move_speed_modifier) == 1: # increased speed modifier -# print("faster faster.") - elif sign(desired_movement_vector.x) == sign(current_x_velocity) and momentum.x != 0: - if sign(acceleration.x) != sign(momentum.x) and x_move_direction_override == 0: - print("Step it up!") - # Flip the direction of the acceleration - acceleration.x *= -1 + print_debug("be more opposite") + + elif (sign(desired_movement_vector.x) == sign(current_x_velocity) and momentum.x != 0): + print('why') + if (sign(acceleration.x) != sign(momentum.x) and x_move_direction_override == 0): + #print("Step it up!") + # Flip the direction of the acceleration + acceleration.x *= -1 # Apply momentum and acceleration if a modifer exists if momentum.x <= 0 and _move_speed_modifier !=0: