Generalized resolve_inertia function. Have a bug on dash after land.
This commit is contained in:
parent
25046c852f
commit
675a0181f0
|
|
@ -132,7 +132,6 @@ func calculate_velocity(_delta :float,
|
||||||
|
|
||||||
## Acceleration is always postive because we use the current inertia
|
## Acceleration is always postive because we use the current inertia
|
||||||
## placement to the movement range to determine direction of movement.
|
## placement to the movement range to determine direction of movement.
|
||||||
#calc_acceleration.x = abs(resolve_h_acceleration(movement_parameters, move_direction.x))
|
|
||||||
if sign(move_direction.x) != 0:
|
if sign(move_direction.x) != 0:
|
||||||
#calc_acceleration.x = abs(movement_parameters.get_acceleration(0).x)
|
#calc_acceleration.x = abs(movement_parameters.get_acceleration(0).x)
|
||||||
calc_acceleration.x = movement_parameters.get_acceleration().x
|
calc_acceleration.x = movement_parameters.get_acceleration().x
|
||||||
|
|
@ -140,59 +139,76 @@ func calculate_velocity(_delta :float,
|
||||||
push_warning("Negative Acceleration shouln't happen")
|
push_warning("Negative Acceleration shouln't happen")
|
||||||
calc_acceleration.x = abs(calc_acceleration.x)
|
calc_acceleration.x = abs(calc_acceleration.x)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if sign(move_direction.y) != 0:
|
if sign(move_direction.y) != 0:
|
||||||
calc_acceleration.y = movement_parameters.get_acceleration().y
|
calc_acceleration.y = movement_parameters.get_acceleration().y
|
||||||
|
|
||||||
|
## Separate impulse function
|
||||||
|
if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
|
||||||
|
#(range_placement :int, inertia :float, impulse_speed_range :Vector2)
|
||||||
|
#_h_impulse_speed_tracking = 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:
|
||||||
|
#var foo = 2+2
|
||||||
|
_h_impulse_speed_tracking = h_speed
|
||||||
|
_h_impulse_applied = true
|
||||||
|
calc_inertia.x = 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
|
||||||
## We are always moving from h_speed.x towards y at a given rate
|
## We are always moving from h_speed.x towards y at a given rate
|
||||||
## if we have a difference of speed and an acceleration
|
## if we have a difference of speed and an acceleration
|
||||||
##TODO: The Min Max could be augmented to just be h_speed.x and prevent the sliding.
|
##TODO: The Min Max could be augmented to just be h_speed.x and prevent the sliding.
|
||||||
if h_speed.x != h_speed.y and calc_acceleration.x != 0.0:
|
calc_inertia.x = resolve_inertia(
|
||||||
var direction_accel :float = calc_acceleration.x * _delta #* move_direction.x
|
h_range_placement,
|
||||||
if h_speed.x > h_speed.y:
|
calc_inertia.x ,
|
||||||
direction_accel *= -1
|
h_speed,
|
||||||
match h_range_placement:
|
(calc_acceleration.x * _delta)
|
||||||
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
|
|
||||||
calc_inertia.x = 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))
|
|
||||||
|
|
||||||
|
## Diabled for single inertia function
|
||||||
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 and calc_acceleration.x != 0.0:
|
||||||
if h_speed.x < h_speed.y:
|
# var direction_accel :float = calc_acceleration.x * _delta #* move_direction.x
|
||||||
h_speed.x = clamp(h_speed.x,0.0,h_speed.y)
|
# if h_speed.x > h_speed.y:
|
||||||
|
# direction_accel *= -1
|
||||||
## Move back towards the base speed
|
# match h_range_placement:
|
||||||
calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, calc_acceleration.x * _delta)
|
# RANGE_PLACEMENT.BEFORE_RANGE:
|
||||||
|
# ## Also apply impulse here
|
||||||
else:
|
# if _h_impulse_applied == false:
|
||||||
## inertia is just base speed
|
# calc_inertia.x += h_speed.x
|
||||||
calc_inertia.x = h_speed.x
|
# _h_impulse_applied = true
|
||||||
calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
#
|
||||||
|
# calc_inertia.x = 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)
|
||||||
|
|
||||||
## 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
|
||||||
|
|
@ -227,7 +243,6 @@ func calculate_velocity(_delta :float,
|
||||||
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
|
||||||
|
|
@ -292,44 +307,6 @@ func placement_to_speed_range(speed: float, speed_range: Vector2) -> int:
|
||||||
return RANGE_PLACEMENT.BEFORE_RANGE
|
return RANGE_PLACEMENT.BEFORE_RANGE
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
## Returns an Vector where x is MIN_SPEED and y is MAX_SPEED
|
|
||||||
func resolve_h_speed(_params :MovementParameters) -> Vector2:
|
|
||||||
# var base_speed :float = _params.base_move_speed.x
|
|
||||||
# ## if a speed difference applies
|
|
||||||
# if _params.move_speed_modifier.x != 0:
|
|
||||||
# var speed_differance = base_speed + _params.move_speed_modifier.x
|
|
||||||
#
|
|
||||||
# return(Vector2(base_speed, speed_differance))
|
|
||||||
# return Vector2(base_speed,base_speed)
|
|
||||||
return Vector2(0,0)
|
|
||||||
|
|
||||||
func resolve_v_speed(_params :MovementParameters) -> Vector2:
|
|
||||||
# var base_speed :float = _params.base_move_speed.y
|
|
||||||
# ## if a speed difference applies
|
|
||||||
# if _params.move_speed_modifier.y != 0:
|
|
||||||
# var speed_differance = base_speed + _params.move_speed_modifier.y
|
|
||||||
#
|
|
||||||
# return(Vector2(base_speed, speed_differance))
|
|
||||||
# return Vector2(base_speed,base_speed)
|
|
||||||
return Vector2(0,0)
|
|
||||||
|
|
||||||
func resolve_h_acceleration(_params :MovementParameters, _move_direction :float) -> float:
|
|
||||||
## TODO: Adjust for jerk, determine if we're currently experiencing accel
|
|
||||||
## if a speed difference applies
|
|
||||||
# var _acceleration :float = 0.0
|
|
||||||
# var base_speed :float = _params.base_move_speed.x
|
|
||||||
# if _params.move_speed_modifier.x != 0:
|
|
||||||
# var speed_differance = base_speed + _params.move_speed_modifier.x
|
|
||||||
# _acceleration = _params.base_move_acceleration.x + _params.move_speed_modifier_acceleration.x
|
|
||||||
#
|
|
||||||
# else:
|
|
||||||
# _acceleration = _params.base_move_acceleration.x
|
|
||||||
#
|
|
||||||
# if sign(_move_direction) != 0:
|
|
||||||
# return _acceleration
|
|
||||||
|
|
||||||
# No accel returned unless intended
|
|
||||||
return 0.0
|
|
||||||
|
|
||||||
func resolve_move_direction(_momentum :Vector2,
|
func resolve_move_direction(_momentum :Vector2,
|
||||||
_movement_direction :Vector2) -> Vector2:
|
_movement_direction :Vector2) -> Vector2:
|
||||||
|
|
@ -347,51 +324,73 @@ func resolve_move_direction(_momentum :Vector2,
|
||||||
|
|
||||||
return Vector2(horizontal_movement_direction, vertical_movement_direction)
|
return Vector2(horizontal_movement_direction, vertical_movement_direction)
|
||||||
|
|
||||||
#func resolve_inertia(range_placement :int, impulse_status :bool , speed_range :Vector2, delta_acceleration :float) -> float:
|
func apply_impulse(range_placement :int, inertia :float, impulse_speed_range :Vector2) -> float:
|
||||||
# #DELTA?
|
match range_placement:
|
||||||
# var inertia :float = 0.0
|
RANGE_PLACEMENT.BEFORE_RANGE:
|
||||||
# if speed_range.x != speed_range.y and delta_acceleration != 0.0:
|
inertia += impulse_speed_range.x
|
||||||
# var direction_accel :float = delta_acceleration #* move_direction.x
|
return inertia
|
||||||
# if speed_range.x > speed_range.y:
|
RANGE_PLACEMENT.WITHIN_RANGE:
|
||||||
# direction_accel *= -1
|
#if impulse_status == false: # and _h_impulse_speed_tracking != impulse_speed:
|
||||||
# match range_placement:
|
## Set inertia to starting speed, we're already in range
|
||||||
# RANGE_PLACEMENT.BEFORE_RANGE:
|
inertia = impulse_speed_range.x
|
||||||
# ## Also apply impulse here
|
return inertia
|
||||||
|
RANGE_PLACEMENT.PAST_RANGE:
|
||||||
|
if abs(impulse_speed_range.x) > abs(impulse_speed_range.y):
|
||||||
|
inertia = impulse_speed_range.x
|
||||||
|
return inertia
|
||||||
|
return inertia
|
||||||
|
|
||||||
|
func resolve_inertia(range_placement :int,
|
||||||
|
inertia :float ,
|
||||||
|
speed_range :Vector2, delta_acceleration :float) -> float:
|
||||||
|
|
||||||
|
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:
|
# if _h_impulse_applied == false:
|
||||||
# calc_inertia.x += h_speed.x
|
# inertia += speed_range.x
|
||||||
# _h_impulse_applied = true
|
# _h_impulse_applied = true
|
||||||
# #impulse_applied_dir = move_direction.x
|
#impulse_applied_dir = move_direction.x
|
||||||
# inertia = clamp(calc_inertia.x + direction_accel,
|
inertia = clamp(inertia + direction_accel,
|
||||||
# min(calc_inertia.x, h_speed.y),
|
min(inertia, speed_range.y),
|
||||||
# max(calc_inertia.x, h_speed.y))
|
max(inertia, speed_range.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 _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
|
# if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
|
||||||
# ## Set inertia to starting speed, we're already in range
|
# ## Set inertia to starting speed, we're already in range
|
||||||
# calc_inertia.x = h_speed.x
|
# calc_inertia.x = h_speed.x
|
||||||
# _h_impulse_applied = true
|
# _h_impulse_applied = true
|
||||||
# calc_inertia.x = clamp(calc_inertia.x + direction_accel,
|
inertia = clamp(inertia + direction_accel,
|
||||||
# min(h_speed.x, h_speed.y),
|
min(inertia, speed_range.y),
|
||||||
# max(h_speed.x, h_speed.y))
|
max(inertia, speed_range.y))
|
||||||
# RANGE_PLACEMENT.PAST_RANGE:
|
RANGE_PLACEMENT.PAST_RANGE:
|
||||||
# if _h_impulse_applied == false and abs(h_speed.x) > abs(h_speed.y):
|
# if _h_impulse_applied == false and abs(speed_range.x) > abs(speed_range.y):
|
||||||
# calc_inertia.x = h_speed.x
|
# inertia = speed_range.x
|
||||||
# _h_impulse_applied = true
|
# _h_impulse_applied = true
|
||||||
# calc_inertia.x = clamp(calc_inertia.x - direction_accel, # Friction
|
inertia = clamp(inertia - direction_accel, # Friction
|
||||||
# min(calc_inertia.x, h_speed.y),
|
min(inertia, speed_range.y),
|
||||||
# max(calc_inertia.x, h_speed.y))
|
max(inertia, speed_range.y))
|
||||||
#
|
|
||||||
#
|
|
||||||
# elif calc_inertia.x != 0.0 and calc_acceleration.x != 0.0: ## We still have inertia but no difference in movement
|
elif inertia != 0.0 and delta_acceleration != 0.0: ## We still have inertia but no difference in movement
|
||||||
# if h_speed.x < h_speed.y:
|
var clamped_speed = speed_range.x
|
||||||
# h_speed.x = clamp(h_speed.x,0.0,h_speed.y)
|
if speed_range.x < speed_range.y:
|
||||||
#
|
clamped_speed.x = clamp(speed_range.x,0.0,speed_range.y)
|
||||||
# ## Move back towards the base speed
|
|
||||||
# calc_inertia.x = move_toward(calc_inertia.x, h_speed.x, calc_acceleration.x * _delta)
|
## Move back towards the base speed
|
||||||
#
|
inertia = move_toward(inertia, clamped_speed.x, delta_acceleration)
|
||||||
# else:
|
|
||||||
# ## inertia is just base speed
|
else:
|
||||||
# calc_inertia.x = h_speed.x
|
## inertia is just base speed
|
||||||
# calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
inertia = speed_range.x
|
||||||
#
|
#calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
||||||
# return 0.0
|
|
||||||
|
return inertia
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user