Momentum can traverse to jump now! Sortof.

This commit is contained in:
Nitsud Yarg 2024-07-06 00:53:19 -07:00
parent 761fe8d66c
commit 4125e9351c
3 changed files with 18 additions and 12 deletions

View File

@ -593,6 +593,7 @@ attack_node = NodePath("../attack")
[node name="jump" type="Node" parent="movement_state_machine" index="3"] [node name="jump" type="Node" parent="movement_state_machine" index="3"]
script = ExtResource( 8 ) script = ExtResource( 8 )
move_speed = 90.0 move_speed = 90.0
move_modifier_move_acceleration = -100.0
animation_sequence = [ "jump" ] animation_sequence = [ "jump" ]
idle_node = NodePath("../idle") idle_node = NodePath("../idle")
fall_node = NodePath("../fall") fall_node = NodePath("../fall")

View File

@ -21,10 +21,6 @@ func enter() -> void:
# if modifier_stack_ref.has(landing_mod): # if modifier_stack_ref.has(landing_mod):
# print("Jump from Landing Mod at: ", modifier_stack_ref.rfind(landing_mod)) # print("Jump from Landing Mod at: ", modifier_stack_ref.rfind(landing_mod))
.enter() .enter()
if previous_speed_multiplier > 1.0:
speed_multiplier = previous_speed_multiplier
else:
speed_multiplier = 1.0
# Apply initial jump velocity on state enter # Apply initial jump velocity on state enter
move_component.velocity.y = -jump_force move_component.velocity.y = -jump_force

View File

@ -334,7 +334,7 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
# The acceleration is differant # The acceleration is differant
# Perhaps it would be better to trigger this on a difference in modifier but they usually go together. # 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 abs(move_component.acceleration.x) != abs(_move_modifier_move_acceleration + _move_acceleration):
if move_component.desired_movement_vector.x != 0: if move_direction:
print("Acceleration changed.", abs(move_component.acceleration.x), "-", (_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 move_component.acceleration.x = _move_modifier_move_acceleration + _move_acceleration
@ -360,21 +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) or (sign(move_component.desired_movement_vector.x) == -1 and
sign(current_x_velocity) == -1): sign(current_x_velocity) == -1):
print("be more opposite") 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: 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): if sign(move_component.acceleration.x) != sign(move_component.momentum.x) and x_move_direction_override == 0:
print("Step it up!") print("Step it up!")
# Flip the direction of the acceleration # Flip the direction of the acceleration
move_component.acceleration.x *= -1 move_component.acceleration.x *= -1
if move_component.momentum.x <= 0 and _move_speed_modifier !=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 we're trying to move but we have no momentum applied currently
if move_component.desired_movement_vector.x != 0: #if move_component.desired_movement_vector.x != 0:
if move_direction:
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. : ##TODO: I don't know where I should actually set the momentum. :
if sign(_move_speed_modifier) == -1: # decreased speed modifier if sign(_move_speed_modifier) == -1: # decreased speed modifier
move_component.momentum.x = 0 move_component.momentum.x = 0
elif sign(_move_speed_modifier) == +1: # increased speed modifier elif sign(_move_speed_modifier) == +1: # increased speed modifier
move_component.momentum.x = abs(move_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. : ##TODO: I don't know where I should actually set the momentum. :
# This was not the place # This was not the place
# if sign(_move_speed_modifier) == -1: # decreased speed modifier # if sign(_move_speed_modifier) == -1: # decreased speed modifier
@ -420,9 +427,11 @@ func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
move_component.momentum.x = clamp(move_component.momentum.x, 0, _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 new_move_speed = _move_speed + move_component.momentum.x # + jerk
else: # physics won't apply here else: # physics won't apply here
move_component.acceleration.x = 0 # move_component.acceleration.x = 0
move_component.momentum.x = 0 # move_component.momentum.x = 0
new_move_speed = _move_speed # 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) #new_move_speed = clamp(new_move_speed, MIN_SPEED, MAX_SPEED)
@ -434,7 +443,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) + ")\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)) + "\nS:" + str(round(_move_speed + _move_speed_modifier)) + ",M" + str(round(move_component.momentum.x)) +
",A" + str(round(move_component.acceleration.x)) + ",A" + str(round(move_component.acceleration.x)) +
"\nVel:" + str(round(move_component.sim_velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED)) "\nVel:" + str(round(move_component.velocity.x)) + "Min:" + str(round(MIN_SPEED)) + ",Max:" + str(round(MAX_SPEED))
) # str(round(jerk)) ) # str(round(jerk))
move_component.sim_velocity.x = move_direction * sim_move_speed move_component.sim_velocity.x = move_direction * sim_move_speed