30 lines
794 B
GDScript

class_name AnimationComponent
extends Node
var animations: AnimationPlayer
var state: StateComponent
func _ready():
state = owner.get_node("State")
state.transitioned.connect(on_transition)
animations = %AnimationPlayer
func _process(delta):
animations.advance(delta)
func on_transition(_from: StateComponent.State, to: StateComponent.State):
match to:
StateComponent.State.Idle:
animations.play("human/idle")
StateComponent.State.Run:
animations.play("human/run-fast")
StateComponent.State.Jump:
animations.play("human/jump")
StateComponent.State.Fall:
animations.play("human/fall")
StateComponent.State.None:
animations.play("human/RESET")
func play(action_name: StringName, speed: float = 1.0):
animations.speed_scale = speed
animations.play(action_name)