Optionaloptions: StateMachinePluginOptions<G>const ecs = ECSpresso.create()
.withPlugin(createStateMachinePlugin())
.build();
const fsm = defineStateMachine('enemy', {
initial: 'idle',
states: {
idle: {
transitions: [{ target: 'chase', guard: ({ ecs, entityId }) => playerNearby(ecs, entityId) }],
},
chase: {
onUpdate: ({ ecs, entityId, dt }) => moveTowardPlayer(ecs, entityId, dt),
on: { playerLost: 'idle' },
},
},
});
ecs.spawn({
...createStateMachine(fsm),
position: { x: 0, y: 0 },
});
Create a state machine plugin for ECSpresso.
Provides:
sendEvent()transitionTo()