diff --git a/src/classes/velocity_controller.gd b/src/classes/velocity_controller.gd index fa435bd..5d6443a 100644 --- a/src/classes/velocity_controller.gd +++ b/src/classes/velocity_controller.gd @@ -89,14 +89,26 @@ func calculate_velocity(_delta :float, (movement_parameters.get_speed_end(NEGATIVE_DIRECTION).x * NEGATIVE_DIRECTION) ) + ## It's time to start treating horizontal and vertical movement the same + var h_speed = Vector2(start_speed, end_speed) #var h_speed = Vector2(movement_parameters.get_speed_start(RELATIVE_DIRECTION).x , movement_parameters.get_speed_end(RELATIVE_DIRECTION).x) #var v_speed = resolve_v_speed(movement_parameters) - var v_speed = Vector2(movement_parameters.get_speed_start(0).y, movement_parameters.get_speed_end(0).y) + start_speed = ( + (movement_parameters.get_speed_start(RELATIVE_DIRECTION).y * move_direction.y) + + (movement_parameters.get_speed_start(POSITIVE_DIRECTION).y * POSITIVE_DIRECTION) + + (movement_parameters.get_speed_start(NEGATIVE_DIRECTION).y * NEGATIVE_DIRECTION) + ) + end_speed = ( + (movement_parameters.get_speed_end(RELATIVE_DIRECTION).y * move_direction.y) + + (movement_parameters.get_speed_end(POSITIVE_DIRECTION).y * POSITIVE_DIRECTION) + + (movement_parameters.get_speed_end(NEGATIVE_DIRECTION).y * NEGATIVE_DIRECTION) + ) + var v_speed = Vector2(start_speed, end_speed) ## Speed will now be expected to move in the direction of travel #h_speed *= move_direction.x - v_speed *= move_direction.y + #v_speed *= move_direction.y ## Now determine placement of current velocity to speed range var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed) @@ -133,7 +145,7 @@ func calculate_velocity(_delta :float, if sign(move_direction.y) != 0: calc_acceleration.y = movement_parameters.get_acceleration().y - if debug and movement_parameters.debug_name == 'move': + if debug and movement_parameters.debug_name == 'fall': 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 @@ -183,7 +195,8 @@ func calculate_velocity(_delta :float, calc_inertial_dir.x = 0.0 # sign(calc_inertia.x) ## Another idea, just return the calculated velocity in PPS - ## For now, y component of velocity is just gravity + ## 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: @@ -196,8 +209,8 @@ func calculate_velocity(_delta :float, _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)) + 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: @@ -208,13 +221,20 @@ func calculate_velocity(_delta :float, 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 + #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 @@ -326,3 +346,52 @@ func resolve_move_direction(_momentum :Vector2, vertical_movement_direction = sign(_momentum.y) return Vector2(horizontal_movement_direction, vertical_movement_direction) + +#func resolve_inertia(range_placement :int, impulse_status :bool , speed_range :Vector2, delta_acceleration :float) -> float: +# #DELTA? +# var inertia :float = 0.0 +# if speed_range.x != speed_range.y and delta_acceleration != 0.0: +# var direction_accel :float = delta_acceleration #* move_direction.x +# if speed_range.x > speed_range.y: +# direction_accel *= -1 +# match range_placement: +# RANGE_PLACEMENT.BEFORE_RANGE: +# ## Also apply impulse here +# if _h_impulse_applied == false: +# calc_inertia.x += h_speed.x +# _h_impulse_applied = true +# #impulse_applied_dir = move_direction.x +# inertia = 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 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)) +# RANGE_PLACEMENT.PAST_RANGE: +# if _h_impulse_applied == false and abs(h_speed.x) > abs(h_speed.y): +# calc_inertia.x = h_speed.x +# _h_impulse_applied = true +# calc_inertia.x = clamp(calc_inertia.x - direction_accel, # Friction +# min(calc_inertia.x, h_speed.y), +# max(calc_inertia.x, h_speed.y)) +# +# +# elif calc_inertia.x != 0.0 and calc_acceleration.x != 0.0: ## We still have inertia but no difference in movement +# if h_speed.x < h_speed.y: +# h_speed.x = clamp(h_speed.x,0.0,h_speed.y) +# +# ## Move back towards the base speed +# calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, calc_acceleration.x * _delta) +# +# else: +# ## inertia is just base speed +# calc_inertia.x = h_speed.x +# calc_inertial_dir.x = 0.0 # sign(calc_inertia.x) +# +# return 0.0