From 07e04383416615c41bf7ff5c35cf2376d5b4f802 Mon Sep 17 00:00:00 2001 From: Dustin Date: Sat, 3 May 2025 21:20:08 -0700 Subject: [PATCH] Kinematic movement process improvements. Hope they stick. --- lib/classes/movement_state_receiver.gd | 47 +++++++++++--------------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/lib/classes/movement_state_receiver.gd b/lib/classes/movement_state_receiver.gd index e908c14..c48dcf4 100644 --- a/lib/classes/movement_state_receiver.gd +++ b/lib/classes/movement_state_receiver.gd @@ -160,18 +160,6 @@ func new_move_actor_as_desired(_delta :float, _state :StateAnimatedActor, _movement_override_normal := Vector2(0,0), _velocity_override := Vector2(0,0)) -> Vector2: - ## Calculated movement speed. - # var movement_params :Dictionary = { - # "_base_h_move_speed" : _state.horizontal_speed, - # "_base_h_move_acceleration" : _state.horizontal_acceleration, - # "_base_h_move_speed_modifier" : _state.horizontal_speed_offset, - # "_base_h_move_modifier_move_acceleration" : _state.horizontal_speed_offset_acceleration, - # "_jerk_factor" : _state.jerk_factor, - # "_gravity" : _state.gravity - # } - var movement_parameters :MovementParameters = _state.get_movement_parameters() - if modifier and modifier.is_active: - movement_parameters.apply_state_modifier(modifier) var calc_velocity = Vector2.ZERO if _velocity_override.x != 0.0: @@ -209,6 +197,10 @@ func new_move_actor_as_desired(_delta :float, impulse_applied_dir = sign(calc_velocity.x) + var movement_parameters :MovementParameters = _state.get_movement_parameters() + if modifier and modifier.is_active: + movement_parameters.apply_state_modifier(modifier) + ## Inertia only applies if there is a difference between the # base move speed and a derived move speed. This makes it so all you # have to do is provide a move speed and that is the speed we will travel. @@ -247,27 +239,34 @@ func new_move_actor_as_desired(_delta :float, ## We are always moving from h_speed.x towards y at a given rate ## if we have a difference of speed and an acceleration if h_speed.x != h_speed.y and calc_acceleration.x != 0.0: - debug_speed_tracker = h_speed ## Start speed really shouldn't be less than zero (modifiers can do this) -# if h_speed.x < h_speed.y: -# h_speed.x = clamp(h_speed.x,0.0,h_speed.y) - + ## If we have mismatched signs we'll get really bad behavior + if sign(h_speed.y) != sign(h_speed.x): + if h_speed.x < h_speed.y: + h_speed.x = clamp(h_speed.x, 0.0, h_speed.y) + else: + h_speed.y = clamp(h_speed.y, 0.0, h_speed.x) + ##TODO: Find a better way to apply impulse on target velocity changes. ## Determine whether we should apply impulse ## If there is currently no inertia apply the base h_speed ## If the direction of our inertia is different to our intended speed direction # and the inertia is not already in range of the movement speed, apply impulse. + # range part is working but we need to also apply it when we have zero + # velocity, hopefully we're at full stop at this point ## if sign(calc_inertia.x) != sign(h_speed.x): ## Only if inertia is not already in range. # if calc_inertia.x <= h_speed.x or calc_inertia.x >= h_speed.y: - if is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y): + if is_out_of_range(calc_inertia.x, h_speed.x, h_speed.y) or h_speed != debug_speed_tracker: ## ? But we only want to do this once though. if impulse_applied == false: + print("Movement Impulse applied: ", h_speed.x) calc_inertia.x += h_speed.x impulse_applied = true impulse_applied_dir = move_direction.x + debug_speed_tracker = h_speed # elif calc_inertia.x != 0.0: # ##WIP: attempts to apply start speed only once # if h_speed.x < h_speed.y: @@ -277,22 +276,14 @@ func new_move_actor_as_desired(_delta :float, # if calc_inertia.x > h_speed.x and sign(move_direction.x) == calc_inertial_dir.x: # calc_inertia.x = h_speed.x + if modifier and modifier.is_active: + var foo = 2+2 # breakpoint check + ## 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, abs(calc_friction.x * _delta)) - if modifier and modifier.is_active: - var foo = 2+2 # breakpoint check - - ## Working but trying something new: -# if h_speed.y > h_speed.x: -# calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, (calc_acceleration.x * _delta)) -# else: -# ## use of move_toward forcing need to apply negative accel as postitive. -# #calc_inertia.x = move_toward(calc_inertia.x, h_speed.y, abs(calc_acceleration.x * _delta)) -# calc_inertia.x = clamp( calc_inertia.x + (calc_acceleration.x * _delta), -# h_speed.y , h_speed.x) elif calc_inertia.x != 0.0 and calc_acceleration.x != 0.0: ## We still have inertia but no difference in movement