class_name StateComponent extends Node enum State { None, Idle, Run, Jump, Fall, Skill, } signal transitioned(from: State, to: State) var movement: MovementComponent var _current: State func _ready(): current = State.Idle movement = owner.get_node("Movement") func _process(_delta): if current == State.Skill: return current = next_state() func next_state() -> State: if movement.body.velocity.y > 0: return State.Jump elif movement.body.velocity.y < 0: return State.Fall elif movement.direction != Vector3.ZERO: return State.Run else: return State.Idle ## Current character state getter and setter. var current: State: get: return _current set(new_state): if _current == new_state: return var old_state := _current _current = new_state transitioned.emit(old_state, new_state)