Game Feel: Input Buffering

A wild jungle seen on an island after shipwrecking from above by a castaway warrior woman.

Game Feel: Input Buffering

A character is midair, headed towards the ground, and you press jump just as they seem to hit the ground. If you press the button too early, the jump is ignored, and your character stands there like a nerd. If you delay the press of the button, something bad might happen. In order to jump exactly when you intend to, you either need perfect timing or else maybe button mashing.

Its not a great experience, so what games typically do is store your inputs for a few frames. If an input is impossible at the time you press it, a 'note' is made about this input, and for a few frames, the game tries to find a way to use that input to smooth over this timing issue. This is called input buffering.

Like many other game feel optimizations, it can be exploited competitively, and is just part of how competitive games are played and designed these days. This is most obvious in the fighting game community, where part of learning to play competitively is understanding how this buffering works in order to perform more difficult move combinations.

Technical Details

The way you implement this is to just create an array for every input the player can enter. Arrays like these are called buffers. If you want X frames of input buffering, you make this array length X (make sure to adjust for players with very high or very low frame rates. You can store input timestamps in an extra large array if this is a likely issue for your game). Every frame, you shift the contents of those arrays by one, so there is a blank spot at the front for you to use, and the oldest input is discarded. You then check which inputs have been entered, store them in this buffer, and the buffering is done.

To actually use those inputs, you create a command executor class of some sort that reads from this buffer, finds some inputs, and figures out what commands might come from them. If an input is used, it is said to be 'consumed,' which means it can't used a second time. In a fighting game, it might be looking for input combinations that activate special moves, and failing that, normal moves, and failing that, movement.

The effect on gameplay can be fairly subtle - animation cancelling makes far more of an impact on the feel of the game, and takes far less work. However, this is still something that almost every fast-paced game should implement.

warrior woman looks into distance at night near a lighthouse by torchlight

About the Author

I'm Nathan. Contract game developer and full stack software developer. E.I.T. Writer. Tabletop RPG designer. Artist. Likes dogs.