From 195b8f064fbc845ba755cbe211148f3b87b1a9a9 Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Fri, 5 Jul 2024 12:14:01 -0700 Subject: [PATCH] Never gonna work is it? --- src/playerD/Player.tscn | 1 - src/state_animated_actor.gd | 186 +++++++++++++++++++----------------- 2 files changed, 96 insertions(+), 91 deletions(-) diff --git a/src/playerD/Player.tscn b/src/playerD/Player.tscn index 07457f8..6dacee8 100644 --- a/src/playerD/Player.tscn +++ b/src/playerD/Player.tscn @@ -621,7 +621,6 @@ script = ExtResource( 11 ) move_speed = 90.0 move_speed_modifier = 90.0 move_modifier_move_acceleration = -180.0 -jerk_factor = -90.0 animation_sequence = [ "dash" ] fall_node = NodePath("../fall") idle_node = NodePath("../idle") diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index cf3b20d..fe12d04 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -280,119 +280,125 @@ 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 = '' + # Allow us to bump out of halt. if _move_speed == 0 and move_component.desired_movement_vector.x != 0: _move_speed = move_component.desired_movement_vector.x - - # Time to start over + + # Determine the maximum move speed + var MAX_SPEED :float = 0 + var MIN_SPEED :float = 0 + if sign(_move_speed_modifier) == -1: # decreased speed modifier + MIN_SPEED = _move_speed + _move_speed_modifier + MAX_SPEED = _move_speed + elif sign(_move_speed_modifier) == +1: # increased speed modifier + MIN_SPEED = _move_speed + MAX_SPEED = _move_speed + _move_speed_modifier + else: # physics won't apply here + #MIN_SPEED = _move_speed + MAX_SPEED = _move_speed + + # Determine or physics movement direction var current_x_velocity = move_component.velocity.x var move_direction = 0.0 - if x_move_direction_override == 0: - move_direction = move_component.desired_movement_vector.x + # Determine movement direction if we have momentum + if move_component.momentum.x != 0: + if x_move_direction_override == 0: + 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 + # # set the move direction to the momentum direction + # move_direction = move_component.momentum.x + else: + move_direction = x_move_direction_override else: - move_direction = x_move_direction_override -# # Determine the maximum move speed -# var max_move_speed = _move_speed + move_speed_modifier + if x_move_direction_override == 0: + move_direction = move_component.desired_movement_vector.x + else: + move_direction = x_move_direction_override - # get the acceleration + # get the latest aggregate acceleration # If we have any acceleration applying if (_move_modifier_move_acceleration + _move_acceleration) != 0: - move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration + if abs(move_component.acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration): + print("Acceleration changed.", abs(move_component.acceleration.x), "-", (_move_modifier_move_acceleration + _move_acceleration)) + move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration - # If we aren't trying to move but we have velocity - if move_direction == 0 and move_component.momentum.x != 0: - if move_component.momentum.x > abs(current_x_velocity): - move_component.momentum.x = current_x_velocity - move_direction = parent.transform.x.x #* - 1 + # 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: - #move_component.momentum.x *= sign(current_x_velocity) - # Reverse the acceleration!? - if sign(move_component.acceleration.x ) == sign(move_component.momentum.x): - move_component.acceleration.x *= -1 + if sign(_move_speed_modifier) == -1 : # decreased speed modifier + if sign(move_direction) == sign(current_x_velocity): + if sign(move_component.acceleration.x) == sign(move_direction): + print("Whoh Woah") + move_component.acceleration.x *= -1 + else: + if sign(move_component.momentum.x) != sign(move_direction): + print("Flip direction ") +# 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 jerk += _jerk_factor * delta + 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, _move_speed_modifier, 0) + 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) + else: # physics won't apply here + move_component.acceleration.x = 0 + move_component.momentum.x = 0 + # If a move speed modifer applies - if _move_speed_modifier != 0: - if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0: - move_component.momentum.x = _move_speed_modifier - #move_component.acceleration.x = 0 - elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0: - move_component.momentum.x = _move_speed_modifier - else: - # We'll adjust our velocity to the move_speed. - if move_component.momentum.x > _move_speed and move_component.acceleration.x > 0: - move_component.momentum.x = 0 - move_component.acceleration.x = 0 - elif move_component.momentum.x < _move_speed and move_component.acceleration.x < 0: - move_component.momentum.x = 0 - move_component.acceleration.x = 0 +# if _move_speed_modifier != 0: +# if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0: +# move_component.momentum.x = _move_speed_modifier +# #move_component.acceleration.x = 0 +# elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0: +# move_component.momentum.x = _move_speed_modifier +# else: +# # We'll adjust our velocity to the move_speed. +# if move_component.momentum.x > _move_speed and move_component.acceleration.x > 0: +# move_component.momentum.x = 0 +# move_component.acceleration.x = 0 +# elif move_component.momentum.x < _move_speed and move_component.acceleration.x < 0: +# move_component.momentum.x = 0 +# move_component.acceleration.x = 0 var new_move_speed = (_move_speed + _move_speed_modifier ) + move_component.momentum.x + jerk + #new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED) - # We have no speed but left over momentum. -# if _move_speed == 0 and move_component.momentum.x != 0.0: -# # W -# pass -# if (_move_modifier_move_acceleration + _move_acceleration) != 0: -# move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration -# -# if _move_speed == 0 and move_component.momentum.x != 0: -# x_move_direction_override = sign(move_component.momentum.x) -# # Uh determine whether frictin applies!? -# # flip the accelleration -# _move_modifier_move_acceleration = move_component.acceleration.x -# _move_modifier_move_acceleration *= -1 -# _move_speed_modifier *= -1 - -# # Allow us to bump out of halt. -# if _move_speed == 0 and move_component.desired_movement_vector.x != 0: -# _move_speed = move_component.desired_movement_vector.x - - -# # 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 -# move_component.momentum.x += _move_modifier_move_acceleration * delta -# #Another crappy normalization hack -# if move_component.momentum.x > _move_speed_modifier and _move_speed_modifier > 0: -# move_component.momentum.x = _move_speed_modifier -# #move_component.acceleration.x = 0 -# elif move_component.momentum.x < _move_speed_modifier and _move_speed_modifier < 0: -# move_component.momentum.x = _move_speed_modifier -# #move_component.acceleration.x = 0 -# -# # Crappy momentum shutdown routines when the modifier doesn't apply -# if _move_speed_modifier == 0: -# if move_component.momentum.x > 0 and move_component.acceleration.x > 0: -# move_component.momentum.x = 0 -# move_component.acceleration.x = 0 -# elif move_component.momentum.x < 0 and move_component.acceleration.x < 0: -# move_component.momentum.x = 0 -# move_component.acceleration.x = 0 - -# var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + move_component.momentum.x + 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 - #if new_move_speed != move_speed: if move_component.momentum.x != 0: - UiManager.debug_text = "S:" + str(round(new_move_speed)) + ",M" + str(round(move_component.momentum.x)) + ",A" + str(round(move_component.acceleration.x)) # str(round(jerk)) + UiManager.debug_text = ( "Mod(" + str(sign(_move_speed_modifier)) + ") Dir(" + str(sign(move_direction)) + ") Mov(" + str(sign(move_component.desired_movement_vector.x)) + + ")\nS:" + str(round(new_move_speed)) + ",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)) + #print(adjusted_move_speed, ",", new_move_speed, ",", jerk) #print(new_move_speed, " ", adjusted_move_speed)