diff --git a/src/classes/velocity_controller.gd b/src/classes/velocity_controller.gd index 67b8032..b6f3565 100644 --- a/src/classes/velocity_controller.gd +++ b/src/classes/velocity_controller.gd @@ -149,9 +149,16 @@ func calculate_velocity(_delta :float, var impulse_inertia = apply_impulse(h_range_placement, calc_inertia.x, h_speed ) if impulse_inertia != calc_inertia.x: #var foo = 2+2 - _h_impulse_speed_tracking = h_speed + #_h_impulse_speed_tracking = h_speed _h_impulse_applied = true 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,calc_inertia.y, v_speed) + if impulse_inertia != calc_inertia.y: + #_v_impulse_speed_tracking = v_speed + _v_impulse_applied = true + calc_inertia.y = impulse_inertia if debug and movement_parameters.debug_name == 'fall': var foo = 2+2 @@ -164,6 +171,14 @@ func calculate_velocity(_delta :float, h_speed, (calc_acceleration.x * _delta) ) + + calc_inertia.y = resolve_inertia( + v_range_placement, + calc_inertia.y , + v_speed, + (calc_acceleration.y * _delta) + ) + ## Diabled for single inertia function # if h_speed.x != h_speed.y and calc_acceleration.x != 0.0: @@ -213,43 +228,43 @@ func calculate_velocity(_delta :float, ## Another idea, just return the calculated velocity in PPS ## For now, y component of velocity is just gravity ## meaning there's always a downward acceleration so we don't have to check. - if v_speed.x != v_speed.y: ## For now gravity is just the default acceleration - 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.y, v_speed.y), - max(calc_inertia.y, 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: - if _v_impulse_applied == false and abs(v_speed.x) > abs(v_speed.y): - calc_inertia.y = v_speed.y - _v_impulse_applied = true - calc_inertia.y = clamp(calc_inertia.y - direction_accel, # Friction - min(calc_inertia.y, v_speed.y), - max(calc_inertia.y, v_speed.y)) - else: - ## The previous vertical movement methods - #calc_inertia.y += movement_parameters.gravity * _delta - if v_speed.x < v_speed.y: - v_speed.x = clamp(v_speed.x,0.0,v_speed.y) - ## Move back towards the base speed - calc_inertia.y = move_toward(calc_inertia.y, v_speed.x, movement_parameters.gravity * _delta) +# if v_speed.x != v_speed.y: ## For now gravity is just the default acceleration +# 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.y, v_speed.y), +# max(calc_inertia.y, 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: +# if _v_impulse_applied == false and abs(v_speed.x) > abs(v_speed.y): +# calc_inertia.y = v_speed.y +# _v_impulse_applied = true +# calc_inertia.y = clamp(calc_inertia.y - direction_accel, # Friction +# min(calc_inertia.y, v_speed.y), +# max(calc_inertia.y, v_speed.y)) +# else: +# ## The previous vertical movement methods +# #calc_inertia.y += movement_parameters.gravity * _delta +# if v_speed.x < v_speed.y: +# v_speed.x = clamp(v_speed.x,0.0,v_speed.y) +# ## Move back towards the base speed +# calc_inertia.y = move_toward(calc_inertia.y, v_speed.x, movement_parameters.gravity * _delta) ## Track or last speed for in range impulses _h_impulse_speed_tracking = h_speed