Now using unified inertia calculation function for both horizontal and vertical movement! Getting closer, finally.

This commit is contained in:
Dustin 2025-05-25 18:48:04 -07:00
parent 675a0181f0
commit bb3f6f5501

View File

@ -149,9 +149,16 @@ func calculate_velocity(_delta :float,
var impulse_inertia = apply_impulse(h_range_placement, calc_inertia.x, h_speed ) var impulse_inertia = apply_impulse(h_range_placement, calc_inertia.x, h_speed )
if impulse_inertia != calc_inertia.x: if impulse_inertia != calc_inertia.x:
#var foo = 2+2 #var foo = 2+2
_h_impulse_speed_tracking = h_speed #_h_impulse_speed_tracking = h_speed
_h_impulse_applied = true _h_impulse_applied = true
calc_inertia.x = impulse_inertia 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': if debug and movement_parameters.debug_name == 'fall':
var foo = 2+2 var foo = 2+2
@ -164,6 +171,14 @@ func calculate_velocity(_delta :float,
h_speed, h_speed,
(calc_acceleration.x * _delta) (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 ## Diabled for single inertia function
# if h_speed.x != h_speed.y and calc_acceleration.x != 0.0: # 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 ## 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. ## 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 # 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 # var direction_accel :float = movement_parameters.gravity * _delta #* move_direction.x
if v_speed.x > v_speed.y: # if v_speed.x > v_speed.y:
direction_accel *= -1 # direction_accel *= -1
match v_range_placement: # match v_range_placement:
RANGE_PLACEMENT.BEFORE_RANGE: # RANGE_PLACEMENT.BEFORE_RANGE:
## Also apply impulse here # ## Also apply impulse here
if _v_impulse_applied == false: # if _v_impulse_applied == false:
calc_inertia.y += v_speed.x # calc_inertia.y += v_speed.x
_v_impulse_applied = true # _v_impulse_applied = true
#impulse_applied_dir = move_direction.x # #impulse_applied_dir = move_direction.x
calc_inertia.y = clamp(calc_inertia.y + direction_accel, # calc_inertia.y = clamp(calc_inertia.y + direction_accel,
min(calc_inertia.y, v_speed.y), # min(calc_inertia.y, v_speed.y),
max(calc_inertia.y, v_speed.y)) # max(calc_inertia.y, v_speed.y))
RANGE_PLACEMENT.WITHIN_RANGE: # RANGE_PLACEMENT.WITHIN_RANGE:
## If we're within the range but our speed has just changed # ## If we're within the range but our speed has just changed
if _v_impulse_applied == false and _v_impulse_speed_tracking != v_speed: # if _v_impulse_applied == false and _v_impulse_speed_tracking != v_speed:
## Set inertia to starting speed, we're already in range # ## Set inertia to starting speed, we're already in range
calc_inertia.y = v_speed.x # calc_inertia.y = v_speed.x
_v_impulse_applied = true # _v_impulse_applied = true
calc_inertia.y = clamp(calc_inertia.y + direction_accel, # calc_inertia.y = clamp(calc_inertia.y + direction_accel,
min(v_speed.x, v_speed.y), # min(v_speed.x, v_speed.y),
max(v_speed.x, v_speed.y)) # max(v_speed.x, v_speed.y))
RANGE_PLACEMENT.PAST_RANGE: # RANGE_PLACEMENT.PAST_RANGE:
if _v_impulse_applied == false and abs(v_speed.x) > abs(v_speed.y): # if _v_impulse_applied == false and abs(v_speed.x) > abs(v_speed.y):
calc_inertia.y = v_speed.y # calc_inertia.y = v_speed.y
_v_impulse_applied = true # _v_impulse_applied = true
calc_inertia.y = clamp(calc_inertia.y - direction_accel, # Friction # calc_inertia.y = clamp(calc_inertia.y - direction_accel, # Friction
min(calc_inertia.y, v_speed.y), # min(calc_inertia.y, v_speed.y),
max(calc_inertia.y, v_speed.y)) # max(calc_inertia.y, v_speed.y))
else: # else:
## The previous vertical movement methods # ## 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: # if v_speed.x < v_speed.y:
v_speed.x = clamp(v_speed.x,0.0,v_speed.y) # v_speed.x = clamp(v_speed.x,0.0,v_speed.y)
## Move back towards the base speed # ## Move back towards the base speed
calc_inertia.y = move_toward(calc_inertia.y, v_speed.x, movement_parameters.gravity * _delta) # calc_inertia.y = move_toward(calc_inertia.y, v_speed.x, movement_parameters.gravity * _delta)
## Track or last speed for in range impulses ## Track or last speed for in range impulses
_h_impulse_speed_tracking = h_speed _h_impulse_speed_tracking = h_speed