|
|
|
|
@ -23,7 +23,7 @@ export var move_speed_modifier: float = 0
|
|
|
|
|
export var move_modifier_move_acceleration: float = 0
|
|
|
|
|
export var jerk_factor: float = 0
|
|
|
|
|
|
|
|
|
|
#var adjusted_move_speed: float
|
|
|
|
|
var adjusted_move_speed: float
|
|
|
|
|
var jerk: float
|
|
|
|
|
|
|
|
|
|
var physics_modifier :StateModifier
|
|
|
|
|
@ -168,7 +168,7 @@ func enter() -> void:
|
|
|
|
|
update_animation()
|
|
|
|
|
|
|
|
|
|
# Reset movespeed counters
|
|
|
|
|
#move_component.momentum.x = move_speed_modifier
|
|
|
|
|
adjusted_move_speed = move_speed_modifier
|
|
|
|
|
jerk = 0
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
@ -260,7 +260,7 @@ func process_physics(_delta: float) -> State:
|
|
|
|
|
# if animations.frames.get_animation_loop(animations.animation) == false:
|
|
|
|
|
# animation_index += 1
|
|
|
|
|
|
|
|
|
|
func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
|
|
|
|
func move_actor_as_desired(delta: float, x_direction: float = 0):
|
|
|
|
|
|
|
|
|
|
var _move_speed = move_speed
|
|
|
|
|
var _move_speed_modifier = move_speed_modifier
|
|
|
|
|
@ -280,181 +280,66 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
|
|
|
|
|
_move_acceleration += mod_props.move_acceleration
|
|
|
|
|
_move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
|
|
|
|
|
_jerk_factor += mod_props.jerk_factor
|
|
|
|
|
# else:
|
|
|
|
|
# UiManager.debug_text = ''
|
|
|
|
|
|
|
|
|
|
var help_me_not_be_dumb = ''
|
|
|
|
|
|
|
|
|
|
# Allow us to bump out of halt.
|
|
|
|
|
if _move_speed == 0 and move_component.desired_movement_vector.x != 0:
|
|
|
|
|
_move_speed = abs(move_component.desired_movement_vector.x)
|
|
|
|
|
|
|
|
|
|
# Determine the maximum move speed
|
|
|
|
|
var MAX_SPEED :float = 0
|
|
|
|
|
var MIN_SPEED :float = 0
|
|
|
|
|
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
|
|
|
|
help_me_not_be_dumb += '-SpeedMod'
|
|
|
|
|
# Move speed cannot go below zero with modifier applied
|
|
|
|
|
MIN_SPEED = _move_speed + _move_speed_modifier
|
|
|
|
|
# Poor man's clamp
|
|
|
|
|
if MIN_SPEED < 0:
|
|
|
|
|
MIN_SPEED = 0
|
|
|
|
|
MAX_SPEED = _move_speed
|
|
|
|
|
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
|
|
|
|
help_me_not_be_dumb += '+SpeedMod'
|
|
|
|
|
MIN_SPEED = _move_speed
|
|
|
|
|
MAX_SPEED = _move_speed + _move_speed_modifier
|
|
|
|
|
else: # physics won't apply here
|
|
|
|
|
help_me_not_be_dumb += '_Speed' # Neutral Speed
|
|
|
|
|
MIN_SPEED = _move_speed
|
|
|
|
|
MAX_SPEED = _move_speed
|
|
|
|
|
|
|
|
|
|
# Determine or physics movement direction
|
|
|
|
|
var current_x_velocity = move_component.velocity.x #move_component.velocity.x
|
|
|
|
|
var move_direction = 0.0
|
|
|
|
|
# Determine movement direction if we have momentum
|
|
|
|
|
if move_component.momentum.x != 0:
|
|
|
|
|
if x_move_direction_override == 0:
|
|
|
|
|
move_direction = sign(current_x_velocity)
|
|
|
|
|
# if move_component.desired_movement_vector.x != 0:
|
|
|
|
|
# # set the move direction to the desired direction
|
|
|
|
|
# move_direction = move_component.desired_movement_vector.x
|
|
|
|
|
# else:
|
|
|
|
|
# # Set move direction to the transform direction
|
|
|
|
|
# move_direction = parent.transform.x.x
|
|
|
|
|
else:
|
|
|
|
|
move_direction = x_move_direction_override
|
|
|
|
|
else: # No current momentum in place
|
|
|
|
|
if x_move_direction_override == 0:
|
|
|
|
|
move_direction = move_component.desired_movement_vector.x
|
|
|
|
|
else:
|
|
|
|
|
move_direction = x_move_direction_override
|
|
|
|
|
|
|
|
|
|
# get the latest aggregate acceleration
|
|
|
|
|
# If we have any acceleration applying
|
|
|
|
|
if (_move_modifier_move_acceleration + _move_acceleration) != 0:
|
|
|
|
|
# The acceleration is differant
|
|
|
|
|
# Perhaps it would be better to trigger this on a difference in modifier but they usually go together.
|
|
|
|
|
if abs(move_component.acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration):
|
|
|
|
|
if move_direction:
|
|
|
|
|
print("Acceleration changed.", abs(move_component.acceleration.x), "-", (_move_modifier_move_acceleration + _move_acceleration))
|
|
|
|
|
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
|
|
|
|
|
|
|
|
|
# ##TODO: I don't know where I should actually set the momentum. :
|
|
|
|
|
# if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
|
|
|
|
# move_component.momentum.x = 0
|
|
|
|
|
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
|
|
|
|
# move_component.momentum.x = abs(move_speed_modifier)
|
|
|
|
|
|
|
|
|
|
# If we're no longer tryingg to move int the direction of our movement and momentum.
|
|
|
|
|
if sign(current_x_velocity) != sign(move_component.desired_movement_vector.x) and move_component.momentum.x != 0:
|
|
|
|
|
if sign(_move_speed_modifier) == -1 : # decreased speed modifier
|
|
|
|
|
|
|
|
|
|
# Maybe we can compare the direction of the acceleration
|
|
|
|
|
# The direction of the acceleration should usually be positive at this point.
|
|
|
|
|
# when the modifier is negative.
|
|
|
|
|
if sign(move_direction) == sign(current_x_velocity):
|
|
|
|
|
if sign(move_component.acceleration.x) == sign(move_component.momentum.x):
|
|
|
|
|
print("Whoh Woah")
|
|
|
|
|
# Flip the direction of the acceleration
|
|
|
|
|
move_component.acceleration.x *= -1
|
|
|
|
|
if (sign(move_component.desired_movement_vector.x) == -1 and
|
|
|
|
|
sign(current_x_velocity) == 1) or (sign(move_component.desired_movement_vector.x) == -1 and
|
|
|
|
|
sign(current_x_velocity) == -1):
|
|
|
|
|
print("be more opposite")
|
|
|
|
|
if sign(_move_speed_modifier) == 1:
|
|
|
|
|
print("faster faster.")
|
|
|
|
|
elif sign(move_component.desired_movement_vector.x) == sign(current_x_velocity) and move_component.momentum.x != 0:
|
|
|
|
|
if sign(move_component.acceleration.x) != sign(move_component.momentum.x) and x_move_direction_override == 0:
|
|
|
|
|
print("Step it up!")
|
|
|
|
|
# Flip the direction of the acceleration
|
|
|
|
|
move_component.acceleration.x *= -1
|
|
|
|
|
if move_component.momentum.x <= 0 and _move_speed_modifier !=0:
|
|
|
|
|
#if we're trying to move but we have no momentum applied currently
|
|
|
|
|
#if move_component.desired_movement_vector.x != 0:
|
|
|
|
|
if move_direction:
|
|
|
|
|
move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
|
|
|
|
##TODO: I don't know where I should actually set the momentum. :
|
|
|
|
|
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
|
|
|
|
move_component.momentum.x = 0
|
|
|
|
|
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
|
|
|
|
move_component.momentum.x = abs(move_speed_modifier)
|
|
|
|
|
if move_component.momentum.x > 0 and _move_speed_modifier == 0:
|
|
|
|
|
if sign(move_component.acceleration.x) == sign(move_component.momentum.x):
|
|
|
|
|
print("Whoh Woah your done.")
|
|
|
|
|
# Flip the direction of the acceleration
|
|
|
|
|
move_component.acceleration.x *= -1
|
|
|
|
|
##TODO: I don't know where I should actually set the momentum. :
|
|
|
|
|
# This was not the place
|
|
|
|
|
# if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
|
|
|
|
# move_component.momentum.x = 0
|
|
|
|
|
# move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
|
|
|
|
|
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
|
|
|
|
# move_component.momentum.x = abs(move_speed_modifier)
|
|
|
|
|
# elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
|
|
|
|
# print("wait does it matter")
|
|
|
|
|
# else: # physics won't apply here
|
|
|
|
|
# print("uh")
|
|
|
|
|
|
|
|
|
|
# else:
|
|
|
|
|
# print("Direction changed")
|
|
|
|
|
# if move_component.momentum.x > abs(current_x_velocity):
|
|
|
|
|
# move_component.momentum.x = abs(current_x_velocity)
|
|
|
|
|
|
|
|
|
|
# flip the acceleration to apply against the momentum
|
|
|
|
|
#move_component.acceleration.x *= -1 * sign(move_component.momentum.x)
|
|
|
|
|
# If the movement direction changes and we have momentum
|
|
|
|
|
# print("Flip that thing!")
|
|
|
|
|
# move_component.momentum.x *= -1
|
|
|
|
|
# if sign(move_component.acceleration.x ) == sign(_move_speed_modifier):
|
|
|
|
|
# move_component.acceleration.x *= -1 * sign(current_x_velocity)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# We're going to adjust our move speed only to the modifier
|
|
|
|
|
move_component.momentum.x += move_component.acceleration.x * delta
|
|
|
|
|
# Assuming adjusted_move_speed is set to the mood speed modifier on state entry
|
|
|
|
|
# Move speed is the base speed plus the modifier minus the decay adjusted for time
|
|
|
|
|
jerk += _jerk_factor * delta
|
|
|
|
|
adjusted_move_speed += _move_modifier_move_acceleration * delta
|
|
|
|
|
#Another crappy normalization hack
|
|
|
|
|
if adjusted_move_speed > _move_speed_modifier and _move_speed_modifier > 0:
|
|
|
|
|
adjusted_move_speed = _move_speed_modifier
|
|
|
|
|
elif adjusted_move_speed < _move_speed_modifier and _move_speed_modifier < 0:
|
|
|
|
|
adjusted_move_speed = _move_speed_modifier
|
|
|
|
|
if _move_speed_modifier == 0:
|
|
|
|
|
adjusted_move_speed = 0
|
|
|
|
|
|
|
|
|
|
# Momentum should always be the inverse of the speed modifier
|
|
|
|
|
var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + adjusted_move_speed + jerk
|
|
|
|
|
|
|
|
|
|
var new_move_speed :float = 0
|
|
|
|
|
if sign(_move_speed_modifier) == -1: # decreased speed modifier
|
|
|
|
|
# MIN_SPEED = _move_speed + _move_speed_modifier
|
|
|
|
|
# MAX_SPEED = _move_speed
|
|
|
|
|
move_component.momentum.x = clamp(move_component.momentum.x, 0, abs(_move_speed_modifier))
|
|
|
|
|
# new_move_speed = (_move_speed + _move_speed_modifier ) + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
|
|
|
|
|
new_move_speed = MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
|
|
|
|
|
elif sign(_move_speed_modifier) == +1: # increased speed modifier
|
|
|
|
|
# MIN_SPEED = _move_speed
|
|
|
|
|
# MAX_SPEED = _move_speed + _move_speed_modifier
|
|
|
|
|
move_component.momentum.x = clamp(move_component.momentum.x, 0, _move_speed_modifier )
|
|
|
|
|
new_move_speed = _move_speed + move_component.momentum.x # + jerk
|
|
|
|
|
else: # physics won't apply here
|
|
|
|
|
# move_component.acceleration.x = 0
|
|
|
|
|
# move_component.momentum.x = 0
|
|
|
|
|
# new_move_speed = _move_speed
|
|
|
|
|
move_component.momentum.x = clamp(move_component.momentum.x, 0, MIN_SPEED )
|
|
|
|
|
new_move_speed = _move_speed + move_component.momentum.x # + jerk
|
|
|
|
|
|
|
|
|
|
#new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED)
|
|
|
|
|
|
|
|
|
|
var sim_move_speed = (MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x))
|
|
|
|
|
|
|
|
|
|
# if move_component.momentum.x != 0:
|
|
|
|
|
if true:
|
|
|
|
|
UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(move_direction) + ") Vel(" + str(sign(current_x_velocity)) + ") Mov(" + str(sign(move_component.desired_movement_vector.x)) +
|
|
|
|
|
")\nNS:" + str(round(sim_move_speed)) + #" Z:" + str(sign(_move_speed_modifier) * -1 * move_component.momentum.x) +
|
|
|
|
|
"\nS:" + str(round(_move_speed + _move_speed_modifier)) + ",M" + str(round(move_component.momentum.x)) +
|
|
|
|
|
",A" + str(round(move_component.acceleration.x)) +
|
|
|
|
|
"\nVel:" + str(round(move_component.velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED))
|
|
|
|
|
) # str(round(jerk))
|
|
|
|
|
|
|
|
|
|
move_component.sim_velocity.x = move_direction * sim_move_speed
|
|
|
|
|
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
|
|
|
|
# A really crappy normalization to prevent modifying past the base move speed.
|
|
|
|
|
if _move_speed_modifier > 0 and new_move_speed < _move_speed: # positive modifier
|
|
|
|
|
#print("nope1")
|
|
|
|
|
new_move_speed = _move_speed
|
|
|
|
|
#adjusted_move_speed = 0
|
|
|
|
|
elif _move_speed_modifier < 0 and new_move_speed > _move_speed: # negative modifier
|
|
|
|
|
#print("nope2")
|
|
|
|
|
new_move_speed = _move_speed
|
|
|
|
|
#adjusted_move_speed = 0
|
|
|
|
|
else:
|
|
|
|
|
if new_move_speed != move_speed:
|
|
|
|
|
UiManager.debug_text = str(round(adjusted_move_speed)) + "," + str(round(new_move_speed)) + "," + str(round(jerk))
|
|
|
|
|
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk)
|
|
|
|
|
|
|
|
|
|
#print(new_move_speed, " ", adjusted_move_speed)
|
|
|
|
|
|
|
|
|
|
move_component.velocity.y += _gravity * delta
|
|
|
|
|
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
|
|
|
#print(speed_multiplier)
|
|
|
|
|
# move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed
|
|
|
|
|
move_component.velocity.x = move_direction * new_move_speed
|
|
|
|
|
if (x_direction != 0):
|
|
|
|
|
move_component.velocity.x = x_direction * new_move_speed
|
|
|
|
|
else:
|
|
|
|
|
move_component.velocity.x = move_component.desired_movement_vector.x * new_move_speed
|
|
|
|
|
move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# var new_speed = move_speed * speed_multiplier
|
|
|
|
|
# if speed_multiplier > 1.0:
|
|
|
|
|
# speed_multiplier -= delta * speed_multiplier
|
|
|
|
|
# #speed_decay_rate += delta * speed_decay_rate
|
|
|
|
|
#
|
|
|
|
|
# elif speed_multiplier < 1.0:
|
|
|
|
|
# speed_multiplier += delta * speed_multiplier
|
|
|
|
|
# #speed_decay_rate += delta * speed_decay_rate
|
|
|
|
|
#
|
|
|
|
|
# # Deadzone
|
|
|
|
|
# if speed_multiplier < 1.1 and speed_multiplier > 0.9:
|
|
|
|
|
# speed_multiplier = 1.0
|
|
|
|
|
## if (new_speed > move_speed):
|
|
|
|
|
## print("Go Faster Booooy! ", move_speed)
|
|
|
|
|
# move_component.velocity.y += gravity * delta
|
|
|
|
|
# #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
|
|
|
|
|
# move_component.velocity.x = move_component.desired_movement_vector.x * new_speed
|
|
|
|
|
# move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))
|
|
|
|
|
|
|
|
|
|
|