https://github.com/lucarickler/bevy-simple-state-machine
Rudimentary animation state machine system for Bevy Engine
https://github.com/lucarickler/bevy-simple-state-machine
bevy-plugin rust
Last synced: over 1 year ago
JSON representation
Rudimentary animation state machine system for Bevy Engine
- Host: GitHub
- URL: https://github.com/lucarickler/bevy-simple-state-machine
- Owner: LucaRickler
- License: other
- Created: 2022-08-06T15:24:41.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-02-17T21:43:38.000Z (over 2 years ago)
- Last Synced: 2025-03-13T09:51:22.614Z (over 1 year ago)
- Topics: bevy-plugin, rust
- Language: Rust
- Homepage:
- Size: 85 KB
- Stars: 24
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Bevy Simple State Machine
[](https://crates.io/crates/bevy-simple-state-machine)
[](https://docs.rs/bevy-simple-state-machine/)
[](./LICENSE)
Plugin for the [Bevy Engine](https://bevyengine.org) which implements
a rudimentary animation state machine system.
To use this, you have to add the `SimpleStateMachinePlugin` to you app:
```rust
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(SimpleStateMachinePlugin::new());
```
And then insert an `AnimationStateMachine` component on your entities:
```rust
fn setup(mut commands: Commands) {
let starting_state = "idle";
let my_states_map = HashMap::from([
("idle".to_string(), AnimationState{
name: "idle".to_string(),
clip: idle_clip_handle,
interruptible: true,
}),
("run".to_string(), AnimationState{
name: "run".to_string(),
clip: run_clip_handle,
interruptible: true,
}),
]);
let my_states_transitions_vec = vec![
StateMachineTransition::immediate(
AnimationStateRef::from_string("idle"),
AnimationStateRef::from_string("run"),
StateMachineTrigger::from(|vars| vars["run"].is_bool(true)),
),
];
let state_machine_vars = HashMap::from([
("run".to_string(), StateMachineVariableType::Bool(false)),
]);
commands.spawn_bundle(SpatialBundle::default())
.insert(AnimationPlayer::default())
.insert(AnimationStateMachine::new(
starting_state,
my_states_map,
my_states_transitions_vec,
state_machine_vars,
));
}
```
And then you can control it changing the values of the state machine variables
```rust
state_machine.update_variable("run", StateMachineVariableType::Bool(true));
```
## Currently supported features:
- Custom transition conditions
- Transitions from wildcard state AnyState
- Events emitted on transition end
- Internal state machine variables
Currently, transitions end on the same frame they are triggered.
---
## Bevy Compatibility:
| Bevy Version | Plugin Version |
|--------------|----------------------|
| `0.13` | `main` |
| `0.13` | `0.6.0` |
| `0.12` | `0.5.0` |
| `0.11` | `0.4.0` |
| `0.10` | `0.3.0` |
| `0.9` | `0.2.0` |
| `0.8` | `0.1.0` |