#Can anyone help me make a state machine

1 messages · Page 1 of 1 (latest)

wet coyote
#

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```
#

In your state handler you'd call each of the functions needed:

    current_state.process( delta )```
#

So you can see that by switching the current state you're now running a completely different process function.