States for a game
A character in a game is in one state at a time: it idles, runs, jumps, waves. The Flow workspace draws them as a graph: each state plays an animation, and a transition leads from one to another, over a crossfade, when what it waits for comes. The game only sets parameters.
States and transitions
- Open the tab Flow of the bar. + State adds a state that plays an animation no state plays yet; the wedge on its left marks the entry, the state the character starts in.
- With the Arrange tool (Q) a click chooses a state or an arrow, a drag moves a state, a drag elsewhere carries the graph. On the right, a state has its name, its animation, its speed, and whether it plays once and holds its end.
- The Link tool (L) draws a transition: drag from one state to another. Delete takes the chosen state or transition away.
What a transition waits for
Under Parameters, + Parameter adds what the game sets: a number (a speed), a switch (on the ground) or a trigger (jump, fired once and spent). The panel of a chosen transition says what it waits for, all of it together:
- When: conditions on the parameters, a number above, under or equal to a value, a switch on or off, a trigger fired;
- At the end of the animation: the last moment of a state played once, or the end of each lap of one that loops;
- On the event: an event the animation tells, a step or a landing;
- On the box: the start or the end of a range of a box of the Hit workspace, the moment a blow lands.
The Crossfade is how long the animations blend. The transitions are tried in their order, the first that may be taken is: Tried earlier and Tried later change it. A transition from Any state is drawn from a box of its own, and is never taken into the state it would leave.
Play it as a game would
Play the graph plays the character in the corner of the canvas, from its entry; the state it is
in is lit. Its parameters are there to set by hand: a number, a switch, and Fire for a trigger.
The graph is kept in flow.json, carried by the bundle that
pantin build writes, and played by pantin_runtime::flow::Machine; pantin
check names a state whose animation is gone.
A whole character
The example duelist is a graph as a game has one: thirteen states and eight parameters,
speed, grounded, crouch, block, health,
and the triggers jump, attack and hurt. What it shows:
- Order matters: from any state, death is tried first (
healthunder 0.5), then a blow; a jump is tried before a fall, since the game fires jump and leaves the ground at once. - A trigger waits until a transition spends it, so a press during a swing is kept: the first attack
goes on to the second on the event
combo, the second to the third on the boxblade, at the end of its blow. Pressed too late, the swing ends and the combo starts again. - An attack, a jump, a landing and a blow play once and go back at the end of the animation; the shield up is a switch held, with its own key of the draw order.