|
|
|
|
@ -41,17 +41,30 @@ func calculate_velocity(_delta :float,
|
|
|
|
|
## We're now toing to preserve inertia direction
|
|
|
|
|
calc_inertia.x = calc_velocity.x
|
|
|
|
|
calc_inertia.y = calc_velocity.y
|
|
|
|
|
|
|
|
|
|
var calc_inertial_dir = Vector2(sign(calc_velocity.x),sign(calc_velocity.y))
|
|
|
|
|
#var calc_friction :Vector2 = Vector2.ZERO
|
|
|
|
|
|
|
|
|
|
## Determine movement direction
|
|
|
|
|
# If there is an inertia direction from existing velocity and
|
|
|
|
|
# no desired movement we'll continue to travel in that direction.
|
|
|
|
|
##
|
|
|
|
|
## If an override has been passed (we're ignoring input direction
|
|
|
|
|
##TODO: Should preserve initia apply here
|
|
|
|
|
var move_direction = Vector2.ZERO
|
|
|
|
|
move_direction = resolve_move_direction(calc_inertia, _movement_direction)
|
|
|
|
|
move_direction = resolve_move_direction(calc_inertia, _movement_direction)
|
|
|
|
|
|
|
|
|
|
## 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 is_zero_approx(calc_acceleration.x):
|
|
|
|
|
move_direction.x = _movement_direction.x
|
|
|
|
|
|
|
|
|
|
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")
|
|
|
|
|
if is_zero_approx(calc_acceleration.y):
|
|
|
|
|
move_direction.y = _movement_direction.y
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Inertia only applies if there is a difference between the
|
|
|
|
|
@ -92,17 +105,6 @@ func calculate_velocity(_delta :float,
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
## 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
|
|
|
|
|
# Any non zero speed that goes opposite to our inertial direction
|
|
|
|
|
# should only be allowed once.
|
|
|
|
|
@ -147,19 +149,36 @@ func calculate_velocity(_delta :float,
|
|
|
|
|
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
|
|
|
|
|
calc_inertia.x = resolve_inertia(
|
|
|
|
|
h_range_placement,
|
|
|
|
|
calc_inertia.x ,
|
|
|
|
|
h_speed,
|
|
|
|
|
(calc_acceleration.x * _delta)
|
|
|
|
|
)
|
|
|
|
|
if is_zero_approx(calc_acceleration.x) == false:
|
|
|
|
|
calc_inertia.x = resolve_inertia(
|
|
|
|
|
h_range_placement,
|
|
|
|
|
calc_inertia.x ,
|
|
|
|
|
h_speed,
|
|
|
|
|
(calc_acceleration.x * _delta)
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
## Using static move directions insteead of inertial move directions
|
|
|
|
|
# if is_zero_approx(_movement_direction.x) == false:
|
|
|
|
|
# calc_inertia.x = h_speed.x
|
|
|
|
|
# else:
|
|
|
|
|
# calc_inertia.x = 0.0
|
|
|
|
|
calc_inertia.x = h_speed.x
|
|
|
|
|
if debug and movement_parameters.debug_name == 'jump':
|
|
|
|
|
var foo = 2+2
|
|
|
|
|
|
|
|
|
|
calc_inertia.y = resolve_inertia(
|
|
|
|
|
v_range_placement,
|
|
|
|
|
calc_inertia.y ,
|
|
|
|
|
v_speed,
|
|
|
|
|
(calc_acceleration.y * _delta)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if is_zero_approx(calc_acceleration.y) == false:
|
|
|
|
|
calc_inertia.y = resolve_inertia(
|
|
|
|
|
v_range_placement,
|
|
|
|
|
calc_inertia.y ,
|
|
|
|
|
v_speed,
|
|
|
|
|
(calc_acceleration.y * _delta)
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
## Using static move directions insteead of inertial move directions
|
|
|
|
|
# if is_zero_approx(_movement_direction.y) == false:
|
|
|
|
|
# calc_inertia.y = v_speed.x
|
|
|
|
|
calc_inertia.y = v_speed.x
|
|
|
|
|
|
|
|
|
|
## Track or last speed for in range impulses
|
|
|
|
|
# _h_impulse_speed_tracking = h_speed
|
|
|
|
|
@ -262,7 +281,7 @@ 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:
|
|
|
|
|
if speed_range.x != speed_range.y and is_zero_approx(delta_acceleration) == false:
|
|
|
|
|
var direction_accel :float = delta_acceleration #* move_direction.x
|
|
|
|
|
if speed_range.x > speed_range.y:
|
|
|
|
|
direction_accel *= -1
|
|
|
|
|
@ -294,21 +313,22 @@ func resolve_inertia(range_placement :int,
|
|
|
|
|
max(inertia, speed_range.y))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif inertia != 0.0 and delta_acceleration != 0.0: ## We still have inertia but no difference in movement
|
|
|
|
|
elif is_zero_approx(inertia) == false: ## We still have inertia but no difference in movement
|
|
|
|
|
var clamped_speed = speed_range.x
|
|
|
|
|
if speed_range.x < speed_range.y:
|
|
|
|
|
clamped_speed = clamp(speed_range.x,0.0,speed_range.y)
|
|
|
|
|
|
|
|
|
|
## Move back towards the base speed
|
|
|
|
|
inertia = move_toward(inertia, clamped_speed, delta_acceleration)
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
## inertia is just base speed
|
|
|
|
|
inertia = speed_range.x
|
|
|
|
|
#calc_inertial_dir.x = 0.0 # sign(calc_inertia.x)
|
|
|
|
|
##TODO: This hopefully won't happen (the commented else statement) but I wonder
|
|
|
|
|
## if I should do anyting here now.
|
|
|
|
|
# else:
|
|
|
|
|
# ## inertia is just base speed
|
|
|
|
|
# inertia = speed_range.x
|
|
|
|
|
# if debug and speed_range.x == -90:
|
|
|
|
|
# var foo = 2+2
|
|
|
|
|
|
|
|
|
|
return inertia
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|