30 lines
794 B
GDScript3
Raw Normal View History

2024-02-07 22:04:19 +00:00
class_name AnimationComponent
extends Node
2024-02-26 22:50:56 +00:00
var animations: AnimationPlayer
2024-02-15 12:45:17 +00:00
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)
2024-02-26 22:50:56 +00:00
animations = %AnimationPlayer
func _process(delta):
animations.advance(delta)
2024-02-15 12:45:17 +00:00
func on_transition(_from: StateComponent.State, to: StateComponent.State):
match to:
StateComponent.State.Idle:
2024-02-26 22:50:56 +00:00
animations.play("human/idle")
2024-02-15 12:45:17 +00:00
StateComponent.State.Run:
2024-02-26 22:50:56 +00:00
animations.play("human/run-fast")
2024-02-15 12:45:17 +00:00
StateComponent.State.Jump:
2024-02-26 22:50:56 +00:00
animations.play("human/jump")
2024-02-15 12:45:17 +00:00
StateComponent.State.Fall:
2024-02-26 22:50:56 +00:00
animations.play("human/fall")
2024-02-15 12:45:17 +00:00
StateComponent.State.None:
2024-02-26 22:50:56 +00:00
animations.play("human/RESET")
2024-02-15 12:45:17 +00:00
func play(action_name: StringName, speed: float = 1.0):
2024-02-26 22:50:56 +00:00
animations.speed_scale = speed
animations.play(action_name)