Compare commits

..

9 Commits

5 changed files with 181 additions and 64 deletions

View File

@ -17,6 +17,11 @@ var current_movement_state:String
# Since animactor state machine can actually view properties from this type # Since animactor state machine can actually view properties from this type
# I'm thinking about moving the velocity tracker in here instead of player. # I'm thinking about moving the velocity tracker in here instead of player.
var velocity = Vector2(0,0) var velocity = Vector2(0,0)
var momentum = Vector2(0,0)
var acceleration = Vector2(0,0)
var sim_velocity = Vector2(0,0)
#Can't use floats here, switched to constants. #Can't use floats here, switched to constants.
#enum directions {UP = -1, DOWN = 1, LEFT, RIGHT} #enum directions {UP = -1, DOWN = 1, LEFT, RIGHT}

View File

@ -570,7 +570,7 @@ interactable_node = NodePath("../Interactable_Receiver")
[node name="idle" parent="movement_state_machine" index="0"] [node name="idle" parent="movement_state_machine" index="0"]
script = ExtResource( 4 ) script = ExtResource( 4 )
move_speed = 1.0 move_speed = 0.0
animation_sequence = [ "idle" ] animation_sequence = [ "idle" ]
jump_node = NodePath("../jump") jump_node = NodePath("../jump")
attack_node = NodePath("../attack") attack_node = NodePath("../attack")
@ -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")
@ -621,7 +622,6 @@ script = ExtResource( 11 )
move_speed = 90.0 move_speed = 90.0
move_speed_modifier = 90.0 move_speed_modifier = 90.0
move_modifier_move_acceleration = -180.0 move_modifier_move_acceleration = -180.0
jerk_factor = -90.0
animation_sequence = [ "dash" ] animation_sequence = [ "dash" ]
fall_node = NodePath("../fall") fall_node = NodePath("../fall")
idle_node = NodePath("../idle") idle_node = NodePath("../idle")

View File

@ -17,7 +17,8 @@ onready var roll_state: State = get_node(roll_node)
func enter() -> void: func enter() -> void:
.enter() .enter()
# parent.set_hurtbox(true) # parent.set_hurtbox(true)
move_component.velocity.x = 0 #move_component.velocity.x = 0
#move_component.momentum.x *= -1
if debug_state: if debug_state:
print(owner.name, " Move Component: ", move_component.desired_movement_vector.x) print(owner.name, " Move Component: ", move_component.desired_movement_vector.x)
@ -39,7 +40,7 @@ func process_physics(delta: float) -> State:
move_actor_as_desired(delta) move_actor_as_desired(delta)
if move_component.velocity.x != 0.0: if move_component.desired_movement_vector.x != 0 and move_component.velocity.x != 0:
return move_state return move_state
if !parent.is_on_floor(): if !parent.is_on_floor():

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

@ -23,7 +23,7 @@ export var move_speed_modifier: float = 0
export var move_modifier_move_acceleration: float = 0 export var move_modifier_move_acceleration: float = 0
export var jerk_factor: float = 0 export var jerk_factor: float = 0
var adjusted_move_speed: float #var adjusted_move_speed: float
var jerk: float var jerk: float
var physics_modifier :StateModifier var physics_modifier :StateModifier
@ -168,7 +168,7 @@ func enter() -> void:
update_animation() update_animation()
# Reset movespeed counters # Reset movespeed counters
adjusted_move_speed = move_speed_modifier #move_component.momentum.x = move_speed_modifier
jerk = 0 jerk = 0
return return
@ -260,7 +260,7 @@ func process_physics(_delta: float) -> State:
# if animations.frames.get_animation_loop(animations.animation) == false: # if animations.frames.get_animation_loop(animations.animation) == false:
# animation_index += 1 # animation_index += 1
func move_actor_as_desired(delta: float, x_direction: float = 0): func move_actor_as_desired(delta: float, x_move_direction_override: float = 0):
var _move_speed = move_speed var _move_speed = move_speed
var _move_speed_modifier = move_speed_modifier var _move_speed_modifier = move_speed_modifier
@ -280,66 +280,181 @@ func move_actor_as_desired(delta: float, x_direction: float = 0):
_move_acceleration += mod_props.move_acceleration _move_acceleration += mod_props.move_acceleration
_move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration _move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration
_jerk_factor += mod_props.jerk_factor _jerk_factor += mod_props.jerk_factor
# else:
# UiManager.debug_text = ''
# 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
var new_move_speed = (_move_speed + _move_speed_modifier ) + (_move_acceleration * delta) + adjusted_move_speed + jerk 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
jerk += _jerk_factor * delta
# Momentum should always be the inverse of the speed modifier
# 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 var new_move_speed :float = 0
#print("nope1") if sign(_move_speed_modifier) == -1: # decreased speed modifier
new_move_speed = _move_speed # MIN_SPEED = _move_speed + _move_speed_modifier
#adjusted_move_speed = 0 # MAX_SPEED = _move_speed
elif _move_speed_modifier < 0 and new_move_speed > _move_speed: # negative modifier move_component.momentum.x = clamp(move_component.momentum.x, 0, abs(_move_speed_modifier))
#print("nope2") # new_move_speed = (_move_speed + _move_speed_modifier ) + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
new_move_speed = _move_speed new_move_speed = MIN_SPEED + (sign(_move_speed_modifier) * -1 * move_component.momentum.x) # + jerk
#adjusted_move_speed = 0 elif sign(_move_speed_modifier) == +1: # increased speed modifier
else: # MIN_SPEED = _move_speed
if new_move_speed != move_speed: # MAX_SPEED = _move_speed + _move_speed_modifier
UiManager.debug_text = str(round(adjusted_move_speed)) + "," + str(round(new_move_speed)) + "," + str(round(jerk)) move_component.momentum.x = clamp(move_component.momentum.x, 0, _move_speed_modifier )
#print(adjusted_move_speed, ",", new_move_speed, ",", jerk) 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)
#print(new_move_speed, " ", adjusted_move_speed) #print(new_move_speed, " ", adjusted_move_speed)
move_component.velocity.y += _gravity * delta move_component.velocity.y += _gravity * delta
#parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) #parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1))
#print(speed_multiplier) #print(speed_multiplier)
if (x_direction != 0): # move_component.velocity.x = move_component.desired_movement_vector.x * _move_speed
move_component.velocity.x = x_direction * new_move_speed move_component.velocity.x = move_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)) 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))