diff --git a/src/movement_component.gd b/src/movement_component.gd index 8506424..6828e78 100644 --- a/src/movement_component.gd +++ b/src/movement_component.gd @@ -17,6 +17,8 @@ var current_movement_state:String # Since animactor state machine can actually view properties from this type # I'm thinking about moving the velocity tracker in here instead of player. var velocity = Vector2(0,0) +var momentum = Vector2(0,0) +var acceleration = Vector2(0,0) #Can't use floats here, switched to constants. #enum directions {UP = -1, DOWN = 1, LEFT, RIGHT} diff --git a/src/playerD/Player.tscn b/src/playerD/Player.tscn index e9f2884..07457f8 100644 --- a/src/playerD/Player.tscn +++ b/src/playerD/Player.tscn @@ -570,7 +570,7 @@ interactable_node = NodePath("../Interactable_Receiver") [node name="idle" parent="movement_state_machine" index="0"] script = ExtResource( 4 ) -move_speed = 1.0 +move_speed = 0.0 animation_sequence = [ "idle" ] jump_node = NodePath("../jump") attack_node = NodePath("../attack") diff --git a/src/playerD/states/idle.gd b/src/playerD/states/idle.gd index 1175180..2dcc654 100644 --- a/src/playerD/states/idle.gd +++ b/src/playerD/states/idle.gd @@ -18,6 +18,7 @@ func enter() -> void: .enter() # parent.set_hurtbox(true) move_component.velocity.x = 0 + #move_component.momentum.x *= -1 if debug_state: print(owner.name, " Move Component: ", move_component.desired_movement_vector.x) @@ -37,9 +38,9 @@ func process_physics(delta: float) -> State: if move_component.wants_shoot(): return attack_state - move_actor_as_desired(delta) + move_actor_as_desired(delta, parent.transform.x.x * -1) - if move_component.velocity.x != 0.0: + if move_component.desired_movement_vector.x != 0: return move_state if !parent.is_on_floor(): diff --git a/src/state_animated_actor.gd b/src/state_animated_actor.gd index a0e5983..2b8992c 100644 --- a/src/state_animated_actor.gd +++ b/src/state_animated_actor.gd @@ -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 - adjusted_move_speed = move_speed_modifier + move_component.momentum.x = move_speed_modifier jerk = 0 return @@ -264,7 +264,9 @@ func move_actor_as_desired(delta: float, x_direction: float = 0): var _move_speed = move_speed var _move_speed_modifier = move_speed_modifier - var _move_modifier_move_acceleration = move_modifier_move_acceleration + #var _move_modifier_move_acceleration = move_modifier_move_acceleration + if move_modifier_move_acceleration != 0: + move_component.acceleration.x = move_modifier_move_acceleration var _move_acceleration = move_acceleration var _jerk_factor = jerk_factor var _gravity = gravity @@ -278,7 +280,8 @@ func move_actor_as_desired(delta: float, x_direction: float = 0): _move_speed = mod_props.move_speed _move_speed_modifier += mod_props.move_speed_modifier _move_acceleration += mod_props.move_acceleration - _move_modifier_move_acceleration += mod_props.move_modifier_move_acceleration + if move_component.acceleration.x != (mod_props.move_modifier_move_acceleration + move_modifier_move_acceleration): + move_component.acceleration.x = mod_props.move_modifier_move_acceleration + move_modifier_move_acceleration _jerk_factor += mod_props.jerk_factor # else: # UiManager.debug_text = '' @@ -286,16 +289,25 @@ func move_actor_as_desired(delta: float, x_direction: float = 0): # 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_component.acceleration.x * 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_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: - adjusted_move_speed = 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) + adjusted_move_speed + jerk + 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. @@ -309,7 +321,7 @@ func move_actor_as_desired(delta: float, x_direction: float = 0): #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)) + UiManager.debug_text = str(round(move_component.momentum.x)) + "," + str(round(new_move_speed)) + "," + str(round(jerk)) #print(adjusted_move_speed, ",", new_move_speed, ",", jerk) #print(new_move_speed, " ", adjusted_move_speed)