diff --git a/src/classes/velocity_controller.gd b/src/classes/velocity_controller.gd index b6de6da..57d4681 100644 --- a/src/classes/velocity_controller.gd +++ b/src/classes/velocity_controller.gd @@ -13,10 +13,16 @@ enum RANGE_PLACEMENT { PAST_RANGE = 1 } +enum IMPULSE_PLACEMENT { + LEFT_SIDE, + RIGHT_SIDE +} + ## Could these be datatypes or a class? Sure var _h_impulse_applied :bool = false var _h_impulse_speed_tracking :Vector2 +var _h_impulse_placement_tracking :int = -1 var _v_impulse_applied :bool = false var _v_impulse_speed_tracking :Vector2 @@ -111,14 +117,24 @@ func calculate_velocity(_delta :float, ## Reset the impulse when back in range # may also want to reset when hspeed is static if _h_impulse_applied == true: - if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and - _h_impulse_speed_tracking != h_speed): + if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE): + _h_impulse_applied = false if debug: print("Resetting H impulse (Within Range)") + elif (calc_inertia.x < h_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.LEFT_SIDE or + calc_inertia.x >= h_speed.x and _h_impulse_placement_tracking != IMPULSE_PLACEMENT.RIGHT_SIDE): _h_impulse_applied = false - elif(h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE): if debug: - print("Resetting H impulse (Before Range) ", _h_impulse_speed_tracking ) + print("Resetting H impulse (Impulse Placement Change)") + +# if (h_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and +# _h_impulse_speed_tracking != h_speed): +# if debug: +# print("Resetting H impulse (Within Range)") +# _h_impulse_applied = false +# elif(h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE): +# if debug: +# print("Resetting H impulse (Before Range) ", _h_impulse_speed_tracking ) if (v_range_placement == RANGE_PLACEMENT.WITHIN_RANGE and _v_impulse_applied == true and @@ -128,19 +144,43 @@ func calculate_velocity(_delta :float, _v_impulse_applied = false ## Separate impulse function - if _h_impulse_applied == false:# and _h_impulse_speed_tracking != h_speed: + if _h_impulse_applied == false and is_zero_approx(h_speed.x) == false:# and _h_impulse_speed_tracking != h_speed: #(range_placement :int, inertia :float, impulse_speed_range :Vector2) - #_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed ) + #_h_impulse_speed_tracking = apply_impulse(h_range_placement, calc_inertia.x, h_speed ) var impulse_inertia = apply_impulse(h_range_placement, _h_impulse_speed_tracking , h_speed ) - if impulse_inertia != calc_inertia.x: ## We have an impulse to apply + if h_range_placement == RANGE_PLACEMENT.PAST_RANGE and abs(h_speed.x) > abs(h_speed.y): if debug: - print("Applying H impulse: Imp: ", impulse_inertia, ", In:", calc_inertia.x) - #var foo = 2+2 + print("Applying H impulse (Past Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x) _h_impulse_speed_tracking = h_speed _h_impulse_applied = true - ## We want to add impulse in the direction of movement so we need to determine - ## what that is. - calc_inertia.x += impulse_inertia + ## This might not make sense + if (calc_inertia.x + h_speed.x) < h_speed.x: + _h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE + else: + _h_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE + ## We don't blow past the acceleration + calc_inertia.x = h_speed.x + elif h_range_placement == RANGE_PLACEMENT.BEFORE_RANGE: + if debug: + print("Applying H impulse (Before Range): Imp: ", impulse_inertia, ", In:", calc_inertia.x) + _h_impulse_speed_tracking = h_speed + _h_impulse_applied = true + if calc_inertia.x < h_speed.x: + _h_impulse_placement_tracking = IMPULSE_PLACEMENT.LEFT_SIDE + else: + _h_impulse_placement_tracking = IMPULSE_PLACEMENT.RIGHT_SIDE + calc_inertia.x += h_speed.x + + ## F this, didn't work well +# if impulse_inertia != calc_inertia.x: ## We have an impulse to apply +# if debug: +# print("Applying H impulse: Imp: ", impulse_inertia, ", In:", calc_inertia.x) +# #var foo = 2+2 +# _h_impulse_speed_tracking = h_speed +# _h_impulse_applied = true +# ## We want to add impulse in the direction of movement so we need to determine +# ## what that is. +# calc_inertia.x += impulse_inertia if _v_impulse_applied == false:# and _v_impulse_speed_tracking != v_speed: var impulse_inertia = apply_impulse(v_range_placement, _v_impulse_speed_tracking, v_speed)