diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index 05a58b0..dd5718c 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -308,7 +308,7 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): MAX_SPEED = _move_speed # Determine or physics movement direction - var current_x_velocity = move_component.sim_velocity.x #move_component.velocity.x + 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: @@ -332,14 +332,17 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): # 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): - 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 move_component.desired_movement_vector.x != 0: + 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: @@ -357,30 +360,28 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): 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 We're still moving in the direction o -# if sign(move_direction) == sign(current_x_velocity): -# if sign(move_component.acceleration.x) == sign(move_direction): -# print("Whoh Woah") -# # Flip the direction of the acceleration -# move_component.acceleration.x *= -1 -# else: -# # Momentum should shift to the opposite of the move_direction -# if sign(move_component.momentum.x) != (sign(move_direction) * -1): -# move_component.momentum.x *= (sign(move_direction) * -1) -# print("Flip direction ") - else: - if sign(move_component.desired_movement_vector.x) == sign(current_x_velocity): + 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): print("Step it up!") # Flip the direction of the acceleration move_component.acceleration.x *= -1 - if move_component.momentum.x == 0: - ##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 + 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: 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) + ##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) + + ##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 @@ -423,7 +424,7 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): move_component.momentum.x = 0 new_move_speed = _move_speed - new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED) + #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)) @@ -433,7 +434,7 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): ")\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)) + "\nVel:" + str(round(move_component.sim_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 @@ -444,7 +445,7 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0): 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 +# move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed + move_component.velocity.x = move_direction * new_move_speed move_component.velocity = parent.move_and_slide(move_component.velocity, Vector2(0, -1))