From 05580ee50d1b69334ba83ca9e618fdb1d164ced7 Mon Sep 17 00:00:00 2001 From: Dustin Date: Thu, 8 May 2025 21:14:10 -0700 Subject: [PATCH] Vertical application of jump on new range based model. --- lib/classes/movement_state_receiver.gd | 107 +++++++++++++------- src/actors/players/playerE/states/jump.tres | 2 +- 2 files changed, 71 insertions(+), 38 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index 5e218ae..718a20c 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -161,6 +161,12 @@ enum RANGE_PLACEMENT { 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 +var _v_impulse_applied :bool = false +var _v_impulse_speed_tracking :Vector2 + func new_move_actor_as_desired(_delta :float, _state :StateAnimatedActor, _movement_override_normal := Vector2(0,0), @@ -238,10 +244,13 @@ func new_move_actor_as_desired(_delta :float, ## 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 - impulse_applied == true ): - print("resetting impulse") - impulse_applied = false - + _h_impulse_applied == true ): + print("resetting H impulse") + _h_impulse_applied = false + if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and + _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. @@ -273,18 +282,19 @@ func new_move_actor_as_desired(_delta :float, match h_range_placement: RANGE_PLACEMENT.BEFORE_RANGE: ## Also apply impulse here - if impulse_applied == false: + if _h_impulse_applied == false: calc_inertia.x += h_speed.x - impulse_applied = true - impulse_applied_dir = move_direction.x + _h_impulse_applied = true + #impulse_applied_dir = move_direction.x calc_inertia.x = clamp(calc_inertia.x + direction_accel, min(calc_inertia.x, h_speed.y), max(calc_inertia.x, h_speed.y)) RANGE_PLACEMENT.WITHIN_RANGE: - if impulse_applied == false and calc_inertia.x == 0.0: - calc_inertia.x += h_speed.x - impulse_applied = true - impulse_applied_dir = move_direction.x + ## If we're within the range but our speed has just changed + if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed: + ## Set inertia to starting speed, we're already in range + calc_inertia.x = h_speed.x + _h_impulse_applied = true calc_inertia.x = clamp(calc_inertia.x + direction_accel, min(h_speed.x, h_speed.y), max(h_speed.x, h_speed.y)) @@ -312,43 +322,66 @@ func new_move_actor_as_desired(_delta :float, 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 - 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) + var direction_accel :float = movement_parameters.gravity * _delta #* move_direction.x + if v_speed.x > v_speed.y: + direction_accel *= -1 + match v_range_placement: + RANGE_PLACEMENT.BEFORE_RANGE: + ## Also apply impulse here + if _v_impulse_applied == false: + calc_inertia.y += v_speed.x + _v_impulse_applied = true + #impulse_applied_dir = move_direction.x + calc_inertia.y = clamp(calc_inertia.y + direction_accel, + min(calc_inertia.x, v_speed.y), + max(calc_inertia.x, v_speed.y)) + RANGE_PLACEMENT.WITHIN_RANGE: + ## If we're within the range but our speed has just changed + if _v_impulse_applied == false and _v_impulse_speed_tracking != v_speed: + ## Set inertia to starting speed, we're already in range + calc_inertia.y = v_speed.x + _v_impulse_applied = true + calc_inertia.y = clamp(calc_inertia.y + direction_accel, + min(v_speed.x, v_speed.y), + max(v_speed.x, v_speed.y)) + RANGE_PLACEMENT.PAST_RANGE: + calc_inertia.y = clamp(calc_inertia.y - direction_accel, # Friction + 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 + ## Track or last speed for in range impulses + _h_impulse_speed_tracking = h_speed + _v_impulse_speed_tracking = v_speed + 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 - - ## Control, direction can only be controlled when overcome inertia direction. -# 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_velocity.x = calc_inertia.x - ## Attempting to move this to the top - #calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y)) - 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}) + diff --git a/src/actors/players/playerE/states/jump.tres b/src/actors/players/playerE/states/jump.tres index 409b2d9..27416e3 100644 --- a/src/actors/players/playerE/states/jump.tres +++ b/src/actors/players/playerE/states/jump.tres @@ -16,7 +16,7 @@ horizontal_speed_offset_acceleration = 0.0 jerk_factor = 1.0 vertical_speed = 200.0 vertical_acceleration = 0.0 -vertical_speed_offset = -200.0 +vertical_speed_offset = -208.0 vertical_speed_offset_acceleration = 0.0 preserve_inertia = true is_grounded = false