Implementation of a strategy machine for Godot Engine, similar to a state machine but less restrictive (godot 4.1+)
- add a new node
StrategyMachine
node as a child. - add a new node
StrategyController
as a child of theStrategyMachine
node and change the node name. - add a new node
Strategy
as a child of theStrategyMachine
node and change the node name. - extend a new script from
StrategyController
and implement behavior between strategies. - extend a new script from
Strategy
and implement the_enter_strategy
,_exit_strategy
methods.
Turns off the current Strategy
and switches to the strategy with the specified name.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
Enables the Strategy
with the specified name, without affecting the rest of the strategies.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
Disables the Strategy
with the specified name, without affecting the rest of the strategies.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
Enables or disables a specific Strategy
with the specified name.
This function simplifies the use of the machine by abstracting access to the machine's strategies.
Called when the strategy is enabled.
Called when the strategy is disabled.
extends StrategyController
func _ready():
switch_strategy_to("Strategy1")
extends Strategy
func _enter_strategy():
print("Strategy1 enabled")
func _exit_strategy():
print("Strategy1 disabled")