A Walk Cycle Without Drawn Frames, and Feet That Stay Put
A walk is a rule, and code can follow it: a foot on the ground moves back under the hip exactly as fast as the body moves forward, and a foot in the air swings to the front. Drive that rule by the distance the figure has moved, not by the clock, and the feet stop sliding at every speed. Nobody has to draw a frame.
Why do feet slide?
A drawn walk plays at its own pace, say one cycle every 32 frames. The game moves the figure at whatever speed the player asks for. The two only agree at one speed.
In the picture above a full cycle, a step with each foot, covers 16 pixels of ground. A cycle of 32 frames therefore fits a speed of half a pixel a frame. The lower beekeeper moves a whole pixel a frame, so with every frame her standing foot is half a pixel behind where the ground has gone. The upper one has no clock. Her cycle moves on by one sixteenth for every pixel she travels, at any speed, and it stops when she stops.
What is the rule?
The cycle is one number that runs from 0 to 1 and starts again. At 0 the left foot has just come down in front. The right foot does the same half a cycle later.
- On the ground, a foot goes from in front of the hip to behind it in a straight line, as far back as the body goes forward. With the numbers on this page each foot is on the ground for 0.6 of the cycle and reaches 4.8 pixels each way.
- In the air, it swings to the front again and lifts 3 pixels on the way, slow at both ends so that it sets down softly.
- The body is highest when a foot is straight under the hip, and lowest between two steps. Here it rises and sinks by one pixel.
- The arms swing against the legs: the left arm is back when the left foot is in front.
Which feet carry the figure follows from the same number. With each foot on the ground for more than half the cycle, there are moments with both feet down, and that reads as walking. Below one half there are moments with both feet in the air, and that reads as running. The recipe Walk cycle has the code, and its tests walk through every one of those moments.
What does the check say?
The recipe can check a recorded walk: you give it where the figure was and which moment of the cycle it was drawn at, frame by frame, and it follows each standing foot over the ground. We recorded 121 frames of each beekeeper. For the upper one it says:
Checked 121 frames. No foot slides.
For the lower one, whose cycle runs by the clock:
Checked 121 frames. A foot on the ground moves in 120 of them. The worst is frame 2: the left foot stands on the ground and moves 0.5 pixels. The cycle is not in step with how far the figure moves: advance the phase by the distance moved, not by the time passed.
Half a pixel a frame is 30 pixels a second at 60 frames a second, and that is the skating you see.
How is the figure drawn?
Only the beekeeper from the hip up is a drawing, made once, as text:
....yyyy....
...yyyyyy...
...oooooo...
.yyyyyyyyyy.
...ssssss...
...sssskk...
...sssskw...
...ssssss...
...cccccc...
..bcccccc...
..bcccccc...
..bcccccc...
...cccccc...
...cccccc...
The rest is placed by the rule for each frame. A leg is two short lines from the hip to the knee and from the knee to the foot, and the recipe Arm and leg reach says where the knee goes. A boot is three dark pixels at the foot. An arm is a line from the shoulder with a glove at its end. The leg and arm on the far side are drawn first and a shade darker, the body over them, the near leg and arm last.
If your engine wants frames, the rule can write them. We ran the eight frames above through the sprite sheet check:
Sheet of 224 by 26 pixels: 8 frames of 28 by 26.
See-through pixels: 4882. Partly see-through: 0. Colours: 9.
No problems found.
The feet stand on row 24 in every frame, because a foot in the air is always above a foot on the ground. The loop closes, because the eight moments are evenly spaced around the cycle.
What does it not do?
It does not make a walk with character. Every step is the same as the one before, which suits a robot and a crowd and is too even for a hero. A drawn walk can limp, strut or sneak. This one walks.
It also knows nothing about the ground. It assumes the ground is flat and where you say it is. On stairs and slopes each foot needs its own ground height.
And frames written from the rule slide again as soon as an engine plays them by the clock. To keep the feet still, the game has to ask the rule for the moment of the cycle in every frame, or pick the frame by the distance moved.
Paste this to your AI
My character [name] should walk without sliding feet. Build its walk
from a rule instead of drawn frames.
1. First draw the walk as a Mermaid state diagram: which feet carry the
figure, and what moves it from one state to the next. Tell me in one
sentence what drives the cycle in my game right now: time or distance.
2. Take the code "Walk cycle" from
https://spielerando.com/en/recipes/walk-cycle. Run its tests first and
show me that they pass.
3. Drive the cycle by the distance my character moves each frame, and
place the feet, the body and the arms from walkPose.
4. Record 120 frames in which the character walks, slows down, stops and
walks backward. Run checkWalk on them and show me its report word for
word.
5. Only if the report says "No foot slides", tell me it is done. How the
walk looks is for me to judge.
How to check it worked
- Watch one foot and one mark on the ground. While the foot stands, the two must stay together.
- Stop in the middle of a step. The legs must freeze where they are, not finish the step on the spot.
- Walk as slowly as the game allows. A walk by the clock gives itself away here: the legs keep their pace while the figure crawls.
- Walk backward. The cycle should run backward, with the feet still planted.
- Read the report. It has to come from the recording of your game, not from the recipe's own tests.
Was this page helpful?
Next step
Code recipe
Idle sway
When the walker stops, her cycle stops with her and she stands like a cut-out; idle sway lets a standing figure breathe and shift its weight, again without a single drawn frame.