2024-02-07 22:04:19 +00:00
|
|
|
class_name AnimationComponent
|
|
|
|
extends Node
|
|
|
|
|
2024-02-15 12:45:17 +00:00
|
|
|
var player: AnimationPlayer
|
|
|
|
var state: StateComponent
|
2024-02-07 22:04:19 +00:00
|
|
|
|
|
|
|
func _ready():
|
2024-02-15 15:28:27 +00:00
|
|
|
state = owner.get_node("State")
|
2024-02-15 12:45:17 +00:00
|
|
|
state.transitioned.connect(on_transition)
|
|
|
|
player = $AnimationPlayer
|
|
|
|
|
|
|
|
func on_transition(_from: StateComponent.State, to: StateComponent.State):
|
|
|
|
match to:
|
|
|
|
StateComponent.State.Idle:
|
|
|
|
player.play("human/idle")
|
|
|
|
StateComponent.State.Run:
|
|
|
|
player.play("human/run-fast")
|
|
|
|
StateComponent.State.Jump:
|
|
|
|
player.play("human/jump")
|
|
|
|
StateComponent.State.Fall:
|
|
|
|
player.play("human/fall")
|
|
|
|
StateComponent.State.None:
|
|
|
|
player.play("human/RESET")
|
|
|
|
|
|
|
|
func play(action_name: StringName, speed: float = 1.0):
|
|
|
|
player.speed_scale = speed
|
|
|
|
player.play(action_name)
|