Plugin for the Bevy Engine 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_plugin(SimpleStateMachinePlugin::new());
And then insert an AnimationStateMachine
component on your entities:
```rust
fn setup(mut commands: Commands) {
let startingstate = "idle";
let mystatesmap = HashMap::from([
("idle".tostring(), AnimationState{
name: "idle".tostring(),
clip: idlecliphandle,
interruptible: true,
}),
("run".tostring(), AnimationState{
name: "run".tostring(),
clip: runcliphandle,
interruptible: true,
}),
]);
let mystatestransitionsvec = vec![
StateMachineTransition {
startstate: AnimationStateRef::fromstring("idle"),
endstate: AnimationStateRef::fromstring("run"),
trigger: StateMachineTrigger::from(|vars| vars["run"].isbool(true)),
}];
let statemachinevars = HashMap::from([
("run".tostring(), 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, transitions end on the same frame they are triggered.
Animation blending and transition duration are not implemented.
| Bevy Version | Plugin Version |
|--------------|----------------------|
| 0.9
| main
|
| 0.9
| 0.2.0
|
| 0.8
| 0.1.0
|