State machines work by having code that manages the switching of states and then using the current "state" as an entry point for any action that needs to be taken.
For example:
class_name State
## called when you enter the state.
func enter (): -> void:
pass
## called during _process()
func process(delta: float) -> State:
return null
## called during _physics_process
func physics_process(delta: float) -> State:
return null```