- # if we're not stuck, then it's okay to set the velocity
- floor_normal = _player.get_floor_normal()
- ground_slope_input = (PI / 2) - new_velocity.angle_to(floor_normal)
- new_velocity = new_velocity.move_toward(
- move_direction * (walk_speed + ground_slope_input * walk_speed),
- acceleration * delta
- )
- else:
- new_velocity += _player.get_gravity() * air_speed * delta
-
- return new_velocity
+ assign_current_move("idle")
+
+
+func update(input: InputPacket, delta: float):
+ var relevent_move := current_move.should_enter(input)
+ if moves[relevent_move] != current_move:
+ switch_to(relevent_move)
+ current_move.update(input, delta)
+ animation_tree.set_walking_speed(player.velocity.length())
+
+
+func switch_to(state: String):
+ animation_tree.animation_started.disconnect(current_move._on_animation_started)
+ animation_tree.animation_finished.disconnect(current_move._on_animation_finished)
+ current_move.on_exit_state()
+ assign_current_move(state)
+
+
+func assign_current_move(state: String):
+ current_move = moves[state]
+ current_move.on_enter_state()
+
+ animation_tree.animation_started.connect(current_move._on_animation_started)
+ animation_tree.animation_finished.connect(current_move._on_animation_finished)
+ animation_tree.transition(state)
+ player.state = state