Game Feel: Input Buffering

Game Feel: Input Buffering

Your 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 you need a little help.

It's not a great experience when inputs have to be so exacting, so what action games typically do they 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 for Nerds

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 then you can say you have buffered the inputs. Easy.

The hard part is actually using those inputs. To do so, you create a command executor class of some sort that reads from this buffer, finds some inputs, and then figures out what commands might match 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.