Some cleanup of unused code after all that mess.
This commit is contained in:
parent
bb3f6f5501
commit
8960fddef2
|
|
@ -13,11 +13,6 @@ enum RANGE_PLACEMENT {
|
||||||
PAST_RANGE = 1
|
PAST_RANGE = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
## Side effects for these variables
|
|
||||||
# velocity - doesn't change but uses it to set base calculations
|
|
||||||
# accepts the state to determine movement, the deltatime, and an optional direction
|
|
||||||
# Update: Actually should just return movement in PPS
|
|
||||||
##
|
|
||||||
|
|
||||||
## Could these be datatypes or a class? Sure
|
## Could these be datatypes or a class? Sure
|
||||||
var _h_impulse_applied :bool = false
|
var _h_impulse_applied :bool = false
|
||||||
|
|
@ -56,17 +51,8 @@ func calculate_velocity(_delta :float,
|
||||||
##
|
##
|
||||||
## If an override has been passed (we're ignoring input direction
|
## If an override has been passed (we're ignoring input direction
|
||||||
var move_direction = Vector2.ZERO
|
var move_direction = Vector2.ZERO
|
||||||
move_direction = resolve_move_direction(calc_inertia, _movement_direction)
|
move_direction = resolve_move_direction(calc_inertia, _movement_direction)
|
||||||
# else:
|
|
||||||
# move_direction = resolve_move_direction(calc_inertia, desired_movement_vector)
|
|
||||||
|
|
||||||
#var movement_parameters :MovementParameters = _state.get_movement_parameters()
|
|
||||||
# if modifier and modifier.is_active:
|
|
||||||
# if (_state.is_grounded and modifier.only_grounded): # Should we skip
|
|
||||||
# modifier_indicator = '*'
|
|
||||||
# if _state.name == 'jump':
|
|
||||||
# var foo = 2+2 # break
|
|
||||||
# movement_parameters.apply_state_modifier(modifier, move_direction.x)
|
|
||||||
|
|
||||||
## Inertia only applies if there is a difference between the
|
## Inertia only applies if there is a difference between the
|
||||||
# base move speed and a derived move speed. This makes it so all you
|
# base move speed and a derived move speed. This makes it so all you
|
||||||
|
|
@ -77,7 +63,6 @@ func calculate_velocity(_delta :float,
|
||||||
# is the destination speed.
|
# is the destination speed.
|
||||||
# We move towards h_speed.y at the acceleration rate
|
# We move towards h_speed.y at the acceleration rate
|
||||||
##
|
##
|
||||||
#var h_speed = resolve_h_speed(movement_parameters)
|
|
||||||
var start_speed :float = (
|
var start_speed :float = (
|
||||||
(movement_parameters.get_speed_start(RELATIVE_DIRECTION).x * move_direction.x) +
|
(movement_parameters.get_speed_start(RELATIVE_DIRECTION).x * move_direction.x) +
|
||||||
(movement_parameters.get_speed_start(POSITIVE_DIRECTION).x * POSITIVE_DIRECTION) +
|
(movement_parameters.get_speed_start(POSITIVE_DIRECTION).x * POSITIVE_DIRECTION) +
|
||||||
|
|
@ -87,13 +72,9 @@ func calculate_velocity(_delta :float,
|
||||||
(movement_parameters.get_speed_end(RELATIVE_DIRECTION).x * move_direction.x) +
|
(movement_parameters.get_speed_end(RELATIVE_DIRECTION).x * move_direction.x) +
|
||||||
(movement_parameters.get_speed_end(POSITIVE_DIRECTION).x * POSITIVE_DIRECTION) +
|
(movement_parameters.get_speed_end(POSITIVE_DIRECTION).x * POSITIVE_DIRECTION) +
|
||||||
(movement_parameters.get_speed_end(NEGATIVE_DIRECTION).x * NEGATIVE_DIRECTION)
|
(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(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)
|
|
||||||
start_speed = (
|
start_speed = (
|
||||||
(movement_parameters.get_speed_start(RELATIVE_DIRECTION).y * move_direction.y) +
|
(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(POSITIVE_DIRECTION).y * POSITIVE_DIRECTION) +
|
||||||
|
|
@ -106,13 +87,21 @@ func calculate_velocity(_delta :float,
|
||||||
)
|
)
|
||||||
var v_speed = Vector2(start_speed, end_speed)
|
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
|
|
||||||
|
|
||||||
## Now determine placement of current velocity to speed range
|
## Now determine placement of current velocity to speed range
|
||||||
var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed)
|
var h_range_placement = placement_to_speed_range(calc_velocity.x, h_speed)
|
||||||
var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed)
|
var v_range_placement = placement_to_speed_range(calc_velocity.y, v_speed)
|
||||||
|
|
||||||
|
## Acceleration is always postive because we use the current inertia
|
||||||
|
## placement to the movement range to determine direction of movement.
|
||||||
|
if sign(move_direction.x) != 0:
|
||||||
|
#calc_acceleration.x = abs(movement_parameters.get_acceleration(0).x)
|
||||||
|
calc_acceleration.x = movement_parameters.get_acceleration().x
|
||||||
|
assert(calc_acceleration.x >= 0, "Negative X Acceleration shouln't happen")
|
||||||
|
|
||||||
|
if sign(move_direction.y) != 0:
|
||||||
|
calc_acceleration.y = movement_parameters.get_acceleration().y
|
||||||
|
assert(calc_acceleration.y >= 0, "Negative Y Acceleration shouln't happen")
|
||||||
|
|
||||||
## We don't want to be able to scoot our impulse speed to cheat the movement
|
## We don't want to be able to scoot our impulse speed to cheat the movement
|
||||||
# Any non zero speed that goes opposite to our inertial direction
|
# Any non zero speed that goes opposite to our inertial direction
|
||||||
|
|
@ -130,18 +119,6 @@ func calculate_velocity(_delta :float,
|
||||||
print("resetting V impulse")
|
print("resetting V impulse")
|
||||||
_v_impulse_applied = false
|
_v_impulse_applied = false
|
||||||
|
|
||||||
## Acceleration is always postive because we use the current inertia
|
|
||||||
## placement to the movement range to determine direction of movement.
|
|
||||||
if sign(move_direction.x) != 0:
|
|
||||||
#calc_acceleration.x = abs(movement_parameters.get_acceleration(0).x)
|
|
||||||
calc_acceleration.x = movement_parameters.get_acceleration().x
|
|
||||||
if calc_acceleration.x < 0:
|
|
||||||
push_warning("Negative Acceleration shouln't happen")
|
|
||||||
calc_acceleration.x = abs(calc_acceleration.x)
|
|
||||||
|
|
||||||
if sign(move_direction.y) != 0:
|
|
||||||
calc_acceleration.y = movement_parameters.get_acceleration().y
|
|
||||||
|
|
||||||
## Separate impulse function
|
## Separate impulse function
|
||||||
if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
|
if _h_impulse_applied == false and _h_impulse_speed_tracking != h_speed:
|
||||||
#(range_placement :int, inertia :float, impulse_speed_range :Vector2)
|
#(range_placement :int, inertia :float, impulse_speed_range :Vector2)
|
||||||
|
|
@ -164,7 +141,6 @@ func calculate_velocity(_delta :float,
|
||||||
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.
|
|
||||||
calc_inertia.x = resolve_inertia(
|
calc_inertia.x = resolve_inertia(
|
||||||
h_range_placement,
|
h_range_placement,
|
||||||
calc_inertia.x ,
|
calc_inertia.x ,
|
||||||
|
|
@ -179,93 +155,6 @@ func calculate_velocity(_delta :float,
|
||||||
(calc_acceleration.y * _delta)
|
(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
|
|
||||||
# if h_speed.x > h_speed.y:
|
|
||||||
# direction_accel *= -1
|
|
||||||
# match h_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
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
## 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)
|
|
||||||
|
|
||||||
## 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
|
||||||
_v_impulse_speed_tracking = v_speed
|
_v_impulse_speed_tracking = v_speed
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user