Here is a finite state machine behavior for the C3 runtime
https://www.construct.net/make-games/addons/172/fsm-finite-state-machine
Develop games in your browser. Powerful, performant & highly capable.