Idiocode

Dec 2018

Frame Perfect

"Frame perfect" is a term used frequently in speedrunning, and fighting games (like Street Fighter). For a newcomer, the term is mysterious. You will hear expert players throwing it around when talking about the hardest parts of a game. What does it mean to be frame perfect?

It has to do with the time window that a player must send some input to the game. When someone executes a frame perfect trick in a speed run it is because they pressed the right button (or buttons) within some (usually small) amount of time. Typically within a 0.02 second time window. Usually a game is difficult if it requires many frame perfect tricks or combos. Even after playing and watching games that use frame perfect tricks as an indicator of skill, it has been unclear exactly how hard a frame perfect trick is. It is easy for a speedrunner to explain a trick's difficulty simply by saying "That was frame perfect". But is that really enough information to know how hard the trick was?

Maybe by thinking about frame perfectness in terms of probability, we can understand just how hard it is, for different games. Maybe then we could answer:

Is it possible for a person to execute frame perfect tricks reliably? If not, does someone's accuracy rely on chance? If so, what chance does someone have to land a frame perfect trick? How much harder is it to land a one frame in a 60FPS game vs a 30FPS game? What about a 120FPS game? What if the frame rate is not constant (as most, especially older, games are)?

What's in a Frame?!

One degree of difficulty for a "frame perfect" trick relies on the update interval for the particular animation you're interacting with. This update interval is called a "frame". The term "frame" can also refer to a single picture rendered as part of an animation; however, for our purposes the rendering of these frames is unrelated to the update interval (although often they are on the same interval). An update frame is the moment when physics simulations, and input checking is handled within the game. Currently, it is common for this to occur at 60 times per second. This means that inputs to the game, collisions, delays, and other parts of the game's logic are checked every 0.01666 seconds.

There are games that use other update intervals, such as 30 times a second, and games which have glitches that don't have stable update intervals. Instable update intervals can be caused by anything that consumes more priority than the update loop (could be loading models, or physics calculations).

Why have Frame Perfect Tricks?

Frame perfect tricks exist for two reasons: an exploit for speedrunners, or a designed game mechanic. Both reasons introduce a means for some players to perform better at the game if they are able to give the game an input within this small window of one frame.

Exploits

Some frame perfect tricks are due to some race condition or logic error in the game's code. A game may accidentally allow for a player's character execute two inputs at once or in a succession in a way that was not intended. For example, a frame perfect jump command could allow for a player to jump twice instead of only once. The programming error behind many of these exploits involves updating a state after it is used for control flow:

                    
if (character.canJump && jump command was inputted) {
    character.jump();
}

if (character.isStunned) {
    character.canJump = false;
}

if (character.isHit) {
    character.stun(1 second);
}
                    
                

This error (and probably many of the one frame exploits in games) is exploitable because of how a flag is being set below when its usage. The intention of this code was that if the character is hit by an enemy, it is stunned for 1 second and as long as the character is stunned, it cannot jump. However, if the player inputs a jump command on the frame following being hit by an enemy, the player can jump before they are stunned. If inputed any later, the exploit will not work.

The exploit above could be used in a speedrun to continue moving your character even after being hit by an enemy. Perhaps there is a part of the game where it would typically be a slow route due to being stunned by enemies, but a frame perfect trick could turn what would have been a stun into a savings of 1 second. After such an exploit is found, the players who speed runs this game would then attempt to find places to execute this frame perfect trick to achieve a lower time for the speedrun. It is seen that the more frame perfect tricks a game has, the harder the speedrun is. If a game has many frame perfect tricks, the skill cap (the amount of skill required to achieve the absolute best speed run time), is high which results in a more rewarding game.

Skill Barrier

Other games use frame perfect tricks on purpose to introduce a skill barrier. These games make it so that players who are better at executing the frame perfect tricks have a clear advantage over players who can't. Similar to how a first person shooter game places a skill barrier on aiming. Those who can aim better, will perform better at a first person shooter game.

Fighting games such as Street Fighter are a good example of having a skill barrier on frame perfect tricks. In Street Fighter, players can input attack actions for their fighters, and several sequences of attacks can be linked together as a "combo". Different attacks allow for a certain number of frames that the next action of the combo is allowed. These windows of frames can be any number (such as 5 frame combo connections or a 1 frame combo connection), and there is always a delay associated with when the window of frames begins. For example if you use attack A, to connect a combo with attack B, you must wait for 200ms then input attack B within a window of frames after the delay.

Frame perfect tricks are not limited to fighting games. A real-time strategy and platformer game can also have purposefully created frame perfect tricks. A 2D platformer which supports double jumps might have certain jumps that require a frame perfect double jumps (the second jump being at the peak of the first). In this case, every frame would calculate the acceleration of the character based on gravity and the strength of the jump, and there may be a platform to jump to which requires a jump at the exact top of the character's first jump. If there is only one frame where the character is at the peak of their jump, this would be a frame perfect trick.

Probability

One question we set out to answer was "what chance does someone have to land a frame perfect trick?". We can answer this by first making a few assumptions.

  1. The player is able to click a button at a uniform random time within a time window.
  2. The player is able to guess perfectly when this window that contains the target frame starts and ends.

The last assumption should raise an eyebrow because it is not too far from saying "assume the player can do the trick". But for every player, there is some window that they can guess perfectly. If the game makes some sound or animation before the window starts and/or ends, that's a clear sign for the player where the window is. Even if everyone has a different reaction speed, you could add that into the size of the window and keep the assumption. For the same trick, the window size might have different sizes based on the player's reaction speed. A regular player might be certain of windows of size 1/2 seconds, while a new player might only be confident about a window of 1 second.

Static Frame Rates

Let's assume there is a frame perfect trick somewhere within a one second window. If the game updates at 60 FPS, then there is a window of 16.66 ms in that 1 second (1000 ms) window where a frame perfect trick is possible. Then consider a player who has one random button press within the one second window, in an attempt to get a frame perfect trick.

This would give us a probability of 16.66 / 1000 = 1.666% for a one second window. This is if the player is clicking the button at random times, regardless of where the frame perfect interval is during that second.

If you can accurately determine how long a 1 second window of time is you can hit a frame perfect trick 1.666% of the time.

The more accurate the player is to estimating how much time has passed since the beginning of the window, their chances of hitting the frame perfect trick increases. Here is a probability matrix of chances based on the interval the player is capable of determining:

30 FPS 60 FPS 120 FPS
1000 ms 3.33% 1.66% 0.83%
750 ms 4.44% 2.22% 1.11%
500 ms 6.66% 3.33% 1.6%
250 ms 13.33% 6.66% 3.32%
100 ms 33.33% 16.66% 8.33%
50 ms 66.66% 33.33% 16.66%
25 ms 100% 66.66% 33.33%

The left column (interval column) applies to a player if they can accurately determine when an interval of that time has passed. Imagine you were told to yell 500 ms after a light is flashed. This is what is meant by determining how long an interval is. If you can determine 500 ms intervals, and you only have one click to guess when the frame perfect trick is, on a 60 FPS game you will hit the frame perfect trick 3.33% of the time. This is if you only have one chance.

There are frame perfect tricks that can be guessed using more than one button press. If you only must register a button press on the correct frame, and failed button presses are allowed, our chances of landing a frame perfect trick increases greatly. Let's create another probability matrix, this time with number of trials and all for a 60 FPS game.

1 Click 2 Clicks 3 Clicks
1000 ms 1.66% 3.33% 5%
750 ms 2.22% 4.44% 6.66%
500 ms 3.33% 6.66% 10%
250 ms 6.66% 13.33% 20%
100 ms 16.66% 33.33% 50%
50 ms 33.33% 66.66% 100%
25 ms 66.66% 100% 100%

More to come on this later. Have an idea to create a live experiment where you can attempt frame perfect tricks, and see if the numbers above are at all accurate in the real world.