https://github.com/nezvers/statemachine_system_for_godot
Flexible and lightweight StateMachine for Godot
https://github.com/nezvers/statemachine_system_for_godot
gdscript godot machine script state statemachine
Last synced: 7 months ago
JSON representation
Flexible and lightweight StateMachine for Godot
- Host: GitHub
- URL: https://github.com/nezvers/statemachine_system_for_godot
- Owner: nezvers
- License: mit
- Created: 2020-07-17T19:47:33.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-27T18:49:12.000Z (about 5 years ago)
- Last Synced: 2025-02-28T17:46:57.418Z (7 months ago)
- Topics: gdscript, godot, machine, script, state, statemachine
- Language: GDScript
- Homepage:
- Size: 27.3 KB
- Stars: 21
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# State Machine System for Godot
Flexible and lightweight StateMachine for Godot and each system related code row is commented.
States are plain scripts without extending any class except default Reference what GDScript is. States are added to StateMachine through exported script Array. Decision on default State choice must be implemented per use case (Player, Camera, Pickup, Enemy).Project is also simple use case for platformer (Idle, Walk, Jump)
## Usage
* Create StateMachine inherited script for different types of use cases (example - PlayerStateMachine);
* Create State inherited state scripts (example - PlayerState -> PlayerIdle);
* Use virtual functions inheritted from State (unhandled_input, physics_process, process, state_check);
* Add State scripts into StateMachine exported script_array. PlayerStateMachine implements default state choice, you can change it to script_array[0] instead of String key.
* For getting references to nodes or get_tree() use sm (state machine) - yield(sm.get_tree().create_timer(1.0), "timeout")## IMPORTANT
* Each new state needs to implement:
```
func _init(_sm).(_sm)->void:
name = "Idle"
```
## Walkthrough