From fc29c18552af66ed3dde2b921bfb9e5d19f537f4 Mon Sep 17 00:00:00 2001 From: Dustin Date: Thu, 8 May 2025 21:46:24 -0700 Subject: [PATCH] Movement Cleanup. --- lib/classes/movement_state_receiver.gd | 87 ++++--------------- .../playerE/PlayerE-Movement_StateReceiver.gd | 10 +-- 2 files changed, 23 insertions(+), 74 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index 718a20c..f810966 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -156,11 +156,7 @@ enum RANGE_PLACEMENT { # accepts the state to determine movement, the deltatime, and an optional direction # Update: Actually should just return movement in PPS ## -#var calc_inertia = velocity.abs() -#var calc_inertial_dir :Vector2 -var debug_speed_tracker :Vector2 -var impulse_applied_dir :float = 0.0 -var impulse_applied :bool = false + ## Could these be datatypes or a class? Sure var _h_impulse_applied :bool = false var _h_impulse_speed_tracking :Vector2 @@ -171,9 +167,6 @@ func new_move_actor_as_desired(_delta :float, _state :StateAnimatedActor, _movement_override_normal := Vector2(0,0), _velocity_override := Vector2(0,0)) -> Vector2: - - if _state.name == 'jump': - var foo = 2+2 # break var calc_velocity = Vector2.ZERO if _velocity_override.x != 0.0: @@ -205,14 +198,7 @@ func new_move_actor_as_desired(_delta :float, move_direction = resolve_move_direction(calc_inertia, _movement_override_normal) else: move_direction = resolve_move_direction(calc_inertia, desired_movement_vector) - - ##WIP: the impulse logic just doesn't work still, below is another attempt -# if impulse_applied_dir != move_direction.x and sign(calc_velocity.x) != impulse_applied_dir: -# print("resetting impulse") -# impulse_applied = false -# impulse_applied_dir = sign(move_direction.x) - var modifier_indicator := '' var movement_parameters :MovementParameters = _state.get_movement_parameters() if modifier and modifier.is_active: @@ -241,6 +227,9 @@ func new_move_actor_as_desired(_delta :float, var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed) var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed) + ## We don't want to be able to scoot our impulse speed to cheat the movement + # Any non zero speed that goes opposite to our inertial direction + # should only be allowed once. ## Reset the impulse when back in range # may also want to reset when hspeed is static if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and @@ -251,27 +240,11 @@ func new_move_actor_as_desired(_delta :float, _v_impulse_applied == true ): print("resetting V impulse") _v_impulse_applied = false - ## We don't want to be able to scoot our impulse speed to cheat the movement - # Any non zero speed that goes opposite to our inertial direction - # should only be allowed once. ## Acceleration is always postive because we use the # move toward functions. calc_acceleration.x = abs(resolve_h_acceleration(movement_parameters, move_direction.x)) - ## Direction of inertia not equal to move direction - ## 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): -# ## 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 = abs(calc_acceleration.x) -# calc_acceleration.x = 0.0 - #h_speed != debug_speed_tracker ## We are always moving from h_speed.x towards y at a given rate ## if we have a difference of speed and an acceleration ##TODO: The Min Max could be augmented to just be h_speed.x and prevent the sliding. @@ -311,19 +284,11 @@ func new_move_actor_as_desired(_delta :float, ## Move back towards the base speed calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, calc_acceleration.x * _delta) -# if (h_speed != debug_speed_tracker): -# print("Inertia SpeedShift: ", debug_speed_tracker, h_speed, (0.0 == -0.0)) -# debug_speed_tracker = h_speed - else: ## inertia is just base speed calc_inertia.x = h_speed.x calc_inertial_dir.x = 0.0 # sign(calc_inertia.x) - debug_speed_tracker = h_speed -# if move_direction.x == 0: -# calc_inertial_dir.x = sign(h_speed.x) - ## Another idea, just return the calculated velocity in PPS ## For now, y component of velocity is just gravity if v_speed.x != v_speed.y: ## For now gravity is just the default acceleration @@ -354,23 +319,6 @@ func new_move_actor_as_desired(_delta :float, min(calc_inertia.y, v_speed.y), max(calc_inertia.y, v_speed.y)) -# if _state.name == 'jump': -# var _foo = clamp(calc_inertia.y + direction_accel, -# min(v_speed.x, v_speed.y), -# max(v_speed.x, v_speed.y)) -# print ("foo: ", _foo) - - # if (v_speed.x != 0 and v_speed.y != 0) and sign(v_speed.y) != sign(v_speed.x): - # if v_speed.x < v_speed.y: - # v_speed.x = clamp(v_speed.x, 0.0, v_speed.y) - # else: - # v_speed.y = clamp(v_speed.y, 0.0, v_speed.x) - # #print (is_out_of_range(calc_inertia.y, v_speed.x - sign(v_speed.x), v_speed.y - sign(v_speed.y))) - # if is_out_of_range(calc_inertia.y, v_speed.x , v_speed.y): - # ## ? But we only want to do this once though. - # calc_inertia.y += v_speed.x - # ## Apply acceleration - # calc_inertia.y = move_toward(calc_inertia.y, v_speed.y, movement_parameters.gravity * _delta) else: ## The previous vertical movement methods calc_inertia.y += movement_parameters.gravity * _delta @@ -382,19 +330,20 @@ func new_move_actor_as_desired(_delta :float, calc_velocity.y = calc_inertia.y calc_velocity.x = calc_inertia.x - UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + - modifier_indicator + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + - "\nV_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % v_speed.x, "1":"%5.2f" % v_speed.y}) + - "\nSpeedRange : {0}, {1}".format({"0":"%5.2f" % h_range_placement, "1":"%5.2f" % v_range_placement}) + - "\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}) + - #"\nFriction: {0}, {1}".format({"0":"%5.2f" % calc_friction.x, "1":"%5.2f" % calc_friction.y}) + - "\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) + - # h_range_placement - #"\nLength: " + str(velocity.length()) + - "\nMoveDir: {0}, {1}".format({"0":"%4.1f" % move_direction.x, "1":"%4.1f" % move_direction.y}) - ) + if debug_component: + UiManager.debug_text = ( #"H_Speed x Dir: " + str(h_speed) + str('duh') + + modifier_indicator + "H_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % h_speed.x, "1":"%5.2f" % h_speed.y}) + + "\nV_Speed Fm:{0} To:{1}".format({"0":"%5.2f" % v_speed.x, "1":"%5.2f" % v_speed.y}) + + "\nSpeedRange : {0}, {1}".format({"0":"%5.2f" % h_range_placement, "1":"%5.2f" % v_range_placement}) + + "\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}) + + #"\nFriction: {0}, {1}".format({"0":"%5.2f" % calc_friction.x, "1":"%5.2f" % calc_friction.y}) + + "\nAccelCalc : {0}, {1}".format({"0":"%5.2f" % calc_acceleration.x, "1":"%5.2f" % calc_acceleration.y}) + + # h_range_placement + #"\nLength: " + str(velocity.length()) + + "\nMoveDir: {0}, {1}".format({"0":"%4.1f" % move_direction.x, "1":"%4.1f" % move_direction.y}) + ) return calc_velocity diff --git a/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd b/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd index 76d37f4..f016de0 100644 --- a/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd +++ b/src/actors/players/playerE/PlayerE-Movement_StateReceiver.gd @@ -11,12 +11,12 @@ onready var stamina_component = $"%Stamina_Component" var state_stamina_cost :Dictionary func _ready(): - var state_ref :State - var state_name :String - state_name = 'jump' - state_ref = get_node(callable_state_machine).get_state_reference(state_name) + #var state_ref :State + #var state_name :String + #state_name = 'jump' + #state_ref = get_node(callable_state_machine).get_state_reference(state_name) ##TODO Should probably assert here or something. - state_ref.connect("state_entered", self, "_on_state_entered_" + state_name) + #state_ref.connect("state_entered", self, "_on_state_entered_" + state_name) parent_request_state_change = funcref(get_node(callable_state_machine), 'check_parent_before_state_change') if parent.has_method("use_primary_item"):