diff --git a/src/classes/velocity_controller.gd b/src/classes/velocity_controller.gd index 7366334..044820b 100644 --- a/src/classes/velocity_controller.gd +++ b/src/classes/velocity_controller.gd @@ -144,19 +144,27 @@ func calculate_velocity(_delta :float, var foo = 2+2 ## We are always moving from h_speed.x towards y at a given rate ## if we have a difference of speed and an acceleration - calc_inertia.x = resolve_inertia( - h_range_placement, - calc_inertia.x , - h_speed, - (calc_acceleration.x * _delta) - ) - - calc_inertia.y = resolve_inertia( - v_range_placement, - calc_inertia.y , - v_speed, - (calc_acceleration.y * _delta) - ) + if is_zero_approx(calc_acceleration.x) == false: + calc_inertia.x = resolve_inertia( + h_range_placement, + calc_inertia.x , + h_speed, + (calc_acceleration.x * _delta) + ) + else: + if is_zero_approx(move_direction.x) == false: + calc_inertia.x = h_speed.x + + if is_zero_approx(calc_acceleration.y) == false: + calc_inertia.y = resolve_inertia( + v_range_placement, + calc_inertia.y , + v_speed, + (calc_acceleration.y * _delta) + ) + else: + if is_zero_approx(move_direction.y) == false: + calc_inertia.y = v_speed.x ## Track or last speed for in range impulses # _h_impulse_speed_tracking = h_speed @@ -291,22 +299,22 @@ func resolve_inertia(range_placement :int, max(inertia, speed_range.y)) - elif inertia != 0.0 and is_zero_approx(delta_acceleration) == false: ## We still have inertia but no difference in movement + elif is_zero_approx(inertia) == false: ## We still have inertia but no difference in movement var clamped_speed = speed_range.x if speed_range.x < speed_range.y: clamped_speed = clamp(speed_range.x,0.0,speed_range.y) ## Move back towards the base speed inertia = move_toward(inertia, clamped_speed, delta_acceleration) - - else: - ## inertia is just base speed - inertia = speed_range.x - if debug and speed_range.x == -90: - var foo = 2+2 + ##TODO: This hopefully won't happen (the commented else statement) but I wonder + ## if I should do anyting here now. +# else: +# ## inertia is just base speed +# inertia = speed_range.x +# if debug and speed_range.x == -90: +# var foo = 2+2 return inertia -