]> Untitled Git - frog-ninja.git/blobdiff - player/moves/dash.gd
Cleaned up animation associations with states
[frog-ninja.git] / player / moves / dash.gd
index 9ab05839bb4be58f697067b24c8f0418e48c38f1..aaf7081b1837fcfe383dbdc2dbb0eb377fa4b80f 100644 (file)
@@ -2,15 +2,33 @@ extends Move
 class_name Dash
 
 
-func update(input: InputPacket, _delta: float):
-       # Get the XZ input direction based on player's input relative to the camera
-       var forward := camera.global_basis.z
-       var right := camera.global_basis.x
-       var move_direction := (
-               forward * input.movement_direction.y + right * input.movement_direction.x
-               ).normalized()
-       move_direction.y = 0
-
-       # TODO: check if new_pos is valid!
-       var new_pos := player.last_movement_direction * player.dash_length
-       player.global_position += new_pos
+@onready var timer: Timer = $Timer
+
+var finished := false
+var new_position: Vector3
+
+
+func should_enter(input: InputPacket) -> String:
+       if finished:
+               input.actions.sort_custom(moves_priority_sort)
+               return input.actions[0]
+       return "dash"
+
+
+func update(_input: InputPacket, delta: float):
+       player.global_position = lerp(
+               player.global_position,
+               new_position,
+               (player.dash_length / timer.wait_time) * delta
+       )
+
+
+func on_enter_state():
+       player.skin.transition_dash()
+       new_position = player.global_position + player.last_movement_direction * player.dash_length
+       finished = false
+       timer.start()
+
+
+func _on_timer_timeout() -> void:
+       finished = true