Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nofoxtugiv/godot-state-machine
This is a living template for a GoDot Finite State Machine, primarily influenced by Bitlytic's Finite State Machine, but with my own touches and tweaks for my games.
https://github.com/nofoxtugiv/godot-state-machine
game-development game-logic godot godot4 state-machine state-management
Last synced: 13 days ago
JSON representation
This is a living template for a GoDot Finite State Machine, primarily influenced by Bitlytic's Finite State Machine, but with my own touches and tweaks for my games.
- Host: GitHub
- URL: https://github.com/nofoxtugiv/godot-state-machine
- Owner: NoFoxTuGiv
- Created: 2025-01-13T01:27:43.000Z (14 days ago)
- Default Branch: main
- Last Pushed: 2025-01-13T03:45:17.000Z (14 days ago)
- Last Synced: 2025-01-13T04:20:25.359Z (14 days ago)
- Topics: game-development, game-logic, godot, godot4, state-machine, state-management
- Language: GDScript
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GoDot Finite State Machine
This is a living template for a GoDot Finite State Machine, primarily influenced by [Bitlytic](https://youtu.be/ow_Lum-Agbs?si=WMnEHNIlbvq7jt-i)'s Finite State Machine, but with my own touches and tweaks for my games.
This overall template can be used to pick and choose template states to quickly throw together player actions, enemy AI, etc..
## Usage
- Place a State Machine node as a child to the entity (player or ai)
- Add any States needed as children of the State node.
- The State Machine will dynamically add the states to its dictionary## State Machine.gd
The "Brain" which manages the current state and transitions to new states.
### State Machine Parameters
- initial_state (exported): The state the entity should spawn in with.
- current_state: The current running state
- states: A dictionary of all possible states for this entity.### State Machine Functions
- \_ready():
- Adds all child nodes to the states dictionary and sets the entity to the initial state, if provided.
- \_process()
- Calls State.Update(delta)
- \_physics_process()
- Calls Physics_Update(delta)
- on_child_transitioned(state, new_state_name)
- call Exit() on the current state
- call Enter() on the new state
- set the new state to current_state## State.gd
The State Template
### State Parameters
- Transitioned signal
### State Functions
- Enter()
- What to do on entering this state
- Exit()
- What to do on exiting this state
- Update()
- What to do during \_process()
- Physics_Update()
- What to do during \_physics_process()## Idle.gd
An example idle state
### Idle Parameters
- entity
- A reference to this entity (effectively synonymous with self)
- move_speed
- Speed to move at while idling### Idle Functions
- randomize_wander()
- pick an amount of time between 1 and 3 seconds, and a random direction
- Enter()
- call `randomize_wander()`
- Update()
- Keep wandering, calling `randomize_wander()` as needed.
- Physics_Update
- Handle the actual wandering## Follow.gd
An example follow state
### Follow Parameters
- entity
- A reference to this entity (effectively synonymous with self)
- move_speed
- Speed to move at while chasing
- target
- What should this entity chase?### Follow Parameters
- \_ready()
- Set the target entity to the first node in the "Target" group.
- Note: It's very important you add the entity(ies) you'd like to target to a group called "Target" or this will crash. Could probably handle this more gracefully.
- Physics_Update()
- Handle the actual chasing.