Now using unified inertia calculation function for both horizontal and vertical movement! Getting closer, finally.
This commit is contained in:
parent
675a0181f0
commit
bb3f6f5501
|
|
@ -149,10 +149,17 @@ 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
|
||||
## We are always moving from h_speed.x towards y at a given rate
|
||||
|
|
@ -165,6 +172,14 @@ func calculate_velocity(_delta :float,
|
|||
(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:
|
||||
# var direction_accel :float = calc_acceleration.x * _delta #* move_direction.x
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user