r/explainlikeimfive • u/ToeDiscombobulated34 • 5d ago
Technology ELI5 what does it mean when "physics are linked to framerate"?
I understand that when physics are linked to frame rate changing the frame rate of the game can make the physics not act right but that's about it as much as far as my understanding goes, I'm curious why it's done.
452
Upvotes
92
u/alchemyAnalyst 5d ago
I haven't seen a direct answer to the question I assume you're asking, so I'll try my hand at it:
Game developers don't do it very much anymore these days. To my knowledge, it's not considered good practice because we know now that variable framerate is a concern and that it can mess up games that don't account for it.
The reason why game developers used to do it a lot is because running the physics process every frame was just the simplest way of doing things, and they didn't really have to worry about variable framerate for game development as much back then. If you were developing for a single console, you could generally trust that your game would maintain a specific framerate unless it had some edge cases that could cause performance to drop (which you wanted to avoid).
Now, instead of tying things directly to the framerate, many game engines use something referred to as delta time. Delta time is a value provided by the system which basically represents the amount of time that has passed between the previous frame and the current one. Games can use delta time as a multiplier to ensure things happen at a consistent speed from the user's perspective. For example, if a game is expected to run at 30 FPS but it actually runs at 60, any values that scale off of delta time will be automatically cut in half, since one frame at 30 FPS is equal to two frames at 60 FPS.
334
u/aleques-itj 5d ago edited 5d ago
Imagine you want to move a certain distance.
If you code literally moves something by a certain distance every time it runs, you wind up with behavior like:
You want movement to be TIME dependent, not FRAME dependent. You can see this if we scale by the difference in time between frames (there's some gotchas here around this not being exact, but for ELI5 that's the gist of the idea).
If you are referencing GTA 6, this is not what is happening.
The game seems to have a bug on Xbox where you can get the actual timescale knocked into lockstep with the framerate. The entire game itself effectively speeds up or slows down.
So you start getting behavior like:
50
u/Floodhunter345 5d ago
Games need a consistent "clock" to time things. Most displays for a very long time would run at 60 hz (60 refreshes per second, and I'm generalizing). The game can basically set its clock to how often it displays an image on the screen, and use this to time other things like physics effects. Often time finding how far something needs to move in that 1/60th of a second.
There's a lot of generalization in this explanation but that's the gist.
Edit: this makes things potentially difficult when modern displays can easily do more than 60 frames a second. The physics system is not expecting that, so the math starts coming out wrong.
3
u/neoKushan 4d ago
The reason why is because it's a lot simpler to code and test for than dealing with a variable frame rate.
Simpler also means cheaper.
It was less of a problem "back in the day" because computers were a lot slower, so the difference between a high end PC and a low end PC were not that extreme (and some PC's even had a "turbo" button which despite the name was mainly so you can set the CPU back to a more common stock speed), whereas these days the difference is massive.
2
u/Metallicat95 4d ago
In a game, the physics which determine how everything moves must complete all the calculations necessary before a new display frame shows the results.
For most of the history of video games, both the display frame rates and computing power were limited. Games were designed around fixed frame rates, and that rate was often chosen to fit the fastest rate the computations could be done.
With displays often based on televisions, that made the TV frame rates a common limitation, or some fraction of them.
50 or 25 for the PAL/SECAM TV of Europe, 60 or 30 for the NTSC of North America. The rest of the world used one of these two rates.
Note that even this difference is enough to cause a physics change. A 50 frame per second game played on a 60 frame per second system would run 16% faster, if nothing else changed. This affected games imported from other regions.
This didn't go away with HDTV which supports 60 frames worldwide, or computer displays which ran at a wide range of rates because they didn't have to match a TV standard.
Most games built for consoles couldn't get more than 30 or 60 frames per second from their hardware.
That meant that coding the physics to update with those fixed frame rates was efficient. There was no worry about calculations based on variable real time, no need to adjust for more than the fixed rate.
It has only been very recently that game consoles can deliver more than 60 frames per second or support variable refresh rate displays which run at a wide range of rates.
But computers have been doing that for years. So often a game designed for a console at a fixed frame rate would require major changes to accommodate a higher frame rate, which cost too much to do fully when remaking it for a computer.
The simplest solution was to make the computer stick to a fixed 30 or 60 frame rate too, and that was a common option.
But both current top consoles and computers aren't limited to that frame rate, and gamers have long since learned to take advantage of the "physics linked to frame rate" to to do things impossible at the fixed rates.
At 120 frames per second, the physics must update twice as fast as of frames per second. With no adjustment at all, everything could move twice as fast.
But that issue mostly affects very old games. Most include some compensation for the higher frame rates and faster physics updates.
Because the calculations are complicated, those compensation elements don't always produce the same results at higher frame rates. Doing an update twice as often means applying rounding twice as often, and rounding fractions up means a slight speed boost.
This affected movement in games like Call Of Duty series and the driving physics of things like the GTA series. Basically any game from before 2010 and the variable refresh rate development can be affected.
2
u/chato94 4d ago
Imagine two flip books intended to have the same animation. One is done painstakingly by hand and has only a few dozen pages, and the other was generated using some sort of software (AI or what have you).
When a game has its physics tied to the frame rate, that's equivalent to having some animation be done in a flip book.
You can imagine that the automated book with hundreds or thousands of pages will advance the state of the animation a loooooooooot more than the handmade one, and even more importantly, in both cases, the animation playback speed is tied to however fast or slow you can flip through each sheet (the "physics" are tied to the speed of the flipping of each page of the book).
On the other hand, now imagine you're at some sporting event that's being professionally recorded and your camera of choice is basically a potato.
The game will happen as it happens and no camera in the world will be able to dictate or change the outcome of the event (unless a camera somehow ends up falling onto the field), and anyone's best view of that game besides having a front row seat will be whoever's video or stream of that game that they can get their hands on.
If they pay for the professional broadcast, the could be getting a crisp, 120 fps with slow motion replays and all of the lighting and angles, OR, your garbage video with your finger on the lens and a stadium column blocking half of the good view.
In this second case, the "physics" or the game, happen completely independently of the "frame rate" or video/stream you end up watching of that event.
5
u/pdpi 5d ago
Imagine an object is moving one metre per second. After one second, it’s moved one metre, after two seconds, it’s moved two metres, etc.
Now, imagine that object is also accelerating at 1 metre per second per second.
At 1 fps: after one second, you calculate one frame. The object has moved 1 m, and its speed is now 2 m/s.
At 2 fps: after half a second, you calculate one frame. The object has moved 0.5 m, and its speed is now 1.5 m/s. After another half second, calculate a second frame. The object has moved 0.75 m (for a total of 1.25 m), and its speed is 2 m/s.
As the fps goes up, you see the small, incremental effects of acceleration earlier and earlier, so the object moves further and further in the same amount of time.
This is why game engines typically separate the frame rate from the update rate — rendering happens however fast the GPU can handle, but physics and other such things happen at a fixed rate.
2
u/TheVioletBarry 5d ago edited 5d ago
It means the physics update every time the visuals update.
If you go from 60fps to 120fps, physics objects move twice as fast (ex: 2m per second at 60fps is suddenly 4m per second 120fps). If the physics aren't tied to the framerate, they would move at the same speed regardless of the framerate (ex: a speed of 2m per second at 60fps is still 2m per second at 120fps)
2
u/Pi-Guy 5d ago
It’s done for performance reasons. If your game is running at 30 or 60 fps, it’s detrimental to performance to calculate physical interactions multiple times between frame draws.
1
u/trinity016 5d ago
When a new frame is drawn, objects position needs to be re-calculated and updated, that’s game physics simplified. You don’t want to waste power or doesn’t have enough computing capacity to calculate them more frequently than needed, so on a 30fps game the dev made the design decision that it doesn’t need its physics calculated 60 times per second, because half of the results are “wasted”/not displayed. It’s a design decision to tie physics to frame rate, and it made sense for certain games.
However the downside is later down the line when computing power massively improves over hardware that the game initially targets, when modern computer has surplus capacity to do more calculations, you can’t simply just double the frame rate, because the game physics is tied to it and will make the game plays at 2x speed. Similar to playing 24fps movie at 48fps will just make the movie play at 2x instead of what people want, smoother experience.
1
u/bentthroat 5d ago
Lots of good responses, I’m gonna aim for simpler.
Frame rate is how often the game shows you changes happening on screen. If you had 2fps, lots of changes could be happening, but you’d only see those changes 2 times per second.
Making gameplay slow down when frames slow down can be good, because when you have to respond to something at a specific time, you want to make sure there is actually a frame happening at that time. It would be bad if you died to something you couldn’t see because it happened between frames. It’s also just an easy “clock” to use when other clocks wouldn’t work right.
When you wouldn’t want to use it is if you want the pace of events to be rock-solid even when frames drop, but that’s not always what you want.
1
u/Tapeworm1979 5d ago
So, if you play the original sonic the hedgehog and you take damage while having a lot of rings the game will go into a form of slow motion. Sonic will slowly sail through the air until the rings have left the screen.
This is because the framerate dropped 60fps to 30fps. However the game was locked to 60 and so tried to update sonics movement in 1/60th increments not 1/30.
A frame rate independent system knows how long the last frame frame took and adjusts movement around that and not 1/60. This keeps the game running the same regardless of framerate.
1
u/Silvr4Monsters 5d ago
The positions of objects in a screen change with time. This time depends on the framerate. For eg, for frame rate of 1 frame per second the next frame would be the positions after 1second. For 2 fps the next frame is going to be after 0.5seconds, cause now we need 2 frames per second. For 10 FPS, it would be 0.1seconds, etc. the pattern is time for next frame equals 1/number of fps
But we shouldn’t use the fps in the actual calculation. Cause sometimes the frame calculation takes longer than this time. In those cases the system needs to adjust the values based on the adjusted framerate. This is one of the major known bugs, cause it’s a natural way to think about this calculation. So almost everyone who learns to create an engine would come across this problem. But none of the solutions are simple
But this isn’t the only one. In the past some games have been known to be calculated based on processor clock speed. So when emulators came, you could run it at a lower processor speed and it would slow down like bullet time but for the whole game and players could beat the game so much more easily
And ofc when it comes to programming you can have other kinds of bugs too. But these are the famous ones, in my opinion
1
u/manonthemiddle 5d ago
It is like a flipbook where every page moves an object exactly one inch instead of checking a clock. On older consoles with fixed hardware, assuming every frame took identical time saved processing power. When modern hardware renders twice as many frames, the world moves twice as fast.
1
u/Anagoth9 4d ago
Many physics functions (in computer games and real life) are defined in one way or another as changes over time.
For example:
Force = mass x acceleration
Acceleration is the rate in charge of velocity over time.
If a computer program defines time in such a way that it's measured by the frame rate, then changing the frame rate will have a cascading effect on anything that's calculated based on the passage of time.
1
u/Impossible_Dog_7262 4d ago
So imagine you make a game where you run the physics engine every 30th of a second, and the graphics engine every 30th of a second. And because those numbers are the same, you use the same clock for both. But now imagine that you hand this game off to someone who isn't aware you did that, and adds an option to run the graphics every 60th of a second instead. The end result is that all the physics in the game happen at twice the speed.
This is physics being linked to framerate. It is almost always undesirable and most game engines steer you clear away from doing that, so you won't see it much anymore.
1
u/PckMan 4d ago
For every frame your monitor shows you of the game world you're seeing, the system has to run a series of complex simulations for each and every one of those frames, to know what happens between one and the next and show this to you.
So the gameworld is essentially simulated against the "clock" of your framerate, as the framerate dictates how many times per second the calculations have to occur.
So that then poses a critical design question, what will your "fixed" reference be. If the fixed reference is the frame rate itself, this means that every simulation is tied to the frame rate. So you need a stable framerate that functions as the clock for the world, which means that if the framerate changes, the passage of time in the gameworld also changes. So when something like physics is tied to frame rate, then internally something like gravity (objects falling at 10m/s), becomes objects falling at 10m per however many frames you have per second, which means that if you're running the game at double the intended frame rate, it also accelerates gravity and other physics as a result.
The alternative is to use a different internal clock that calculations are tied to that's not pegged to the framerate, so that regardless of the game's framerate events and calculations in the game happen according to a real time clock.
1
u/A_Garbage_Truck 4d ago edited 4d ago
its a proactice some older games and now more recent ones, used ot do in order ot simplify development/lazyness.
because these developers knew that their games were gonna be played with fixed frame rates, they could reasonably link the physics ot the game logic and not have issues assuming the frame rate is stable. this means you dont have ot keep track of physics on a separate loop and synch the physics and game logic into a single update loop.
but what happens if your game/system is changed to be able ot provide a much higher frame rate than originally intended?
if the physics is linked to the framerate, its now updating at the same rate, which will create wildly different results than expected and might make the game unplayable.
an example of the game that handles this poorly: the old unreal tournament games did this before they were patched for modern Pcs, if you tried ot run a pure installation on Unreal tournament 99 in a win 10 pc without patching it, the game would be unplayable(and funny enough if you jumped you immediately died to fall damage), everything would run way too fast.(think 300+ fps while ALL of the logic updating at the same rate.)
antoher Example that handles it better?: the trackmania games have completely deterministic physics: the same inputs will always generate the same results no matter what, so frame rate is irrelevant, fi the inputs are not tampered with, the outcome is the same.
1
u/Sangypboi 2d ago
This isn't common anymore, but older games used systems that relied on specific passive polling events. Physics being linked to framerate, for example, would mean that if you increase the framerate, the physics happen faster because they were programmed with a value of Y-change per frame in a game designed to have a locked frame rate.
This was primarily common in the days when game frame rates were dictated by the power grid. All home consoles originally ran at 60fps. This was for the same reason all CRT tvs ran at 60hz. The power grid was 120 AC current, which means it actually completed a full cycle 60 times per second. Except in Europe where they ran at 50hz (and 50fps) so every game was 16.7% slower in Europe for decades.
•
u/GrossInsightfulness 4h ago
The code for the simplest games with physics you can imagine looks like
Now, you pretty much have to do these tasks in roughly this order, with gameplay scripts maybe showing up in other spots and things like switching audio with rendering (although a modern game would have audio on its own thread). Simple games and old games that can consistently finish all the tasks within a frame can just run the code exactly as written above. More complex games have to use a bunch of tricks to get all their tasks done such as running different parts of the code in parallel. The time between one frame being rendered and the next being rendered defines the frame rate.
"Moving things around" and "checking for collisions" are what people talk about when they talk about "Physics" in a game. The procedure for moving things around in a game roughly looks like
Note that the time since last update is either fixed at something like 1/60th of a second or given by the real time since the game last updated the position. So, let's say that I'm running forward at a rate of 3 meters per second. After 1/60th of a second, I should be 1/20th of a meter (5 cm) in front of where I started. Once the game moves me forward, then we have to check if I'm in anything like a wall. If I am, I should get moved back until I am no longer in the wall or otherwise get pushed out of the wall. (You can also get other interactions like a grunt sound, an animation where I put my hands up against the wall, etc.). If I, as a game dev, can make sure that nothing will move faster than 3 meters per second, I can make sure my game runs properly by making each wall at least 10 cm (4 inches) thick so that nothing ever ends up closer to the side opposite the wall I started on.
Here's where the problem comes in. Let's say there's a huge lag spike that lasts 0.5 seconds. If the physics engine is tied to the frame rate, then I will travel 1.5 meters between frames. So, the collision detection algorithm will see me on one side of the wall one frame and on the other side the next. At no point would it see me overlapping with the wall, so it doesn't do anything with the collision. This behavior is what you'd want since you want to allow for teleportation in a lot of cases.
There's also a secondary problem that's less common, but still relevant. At a mathematical level, the algorithms used to move things around work better if you have a fixed, small timestep. In particular, you don't want things speeding up or slowing down in an unphysical way, like a ball hanging from a spring bouncing up and down until it goes through the ceiling. You can ensure this doesn't happen by making things conserve things like energy, angular momentum, etc. Doing so requires a special class of algorithms (symplectic integrators) that approximately conserve these quantities. Even if you don't have lag, variations in the time between frames can lead to objects speeding up or slowing down in weird ways. So, even if you tied physics code to the framerate and your game ran faster than 60fps, then you could end up getting different behavior on a system running at 144fps than a system running at 60fps.
Besides not solving this problem, there are two main solutions to this problem, and both involve a fixed timestep.
The first solution leads to skipped frames that are still somewhat real-time. The second solution would not skip frames, but it would be like watching a movie frame by frame.
Either of these solutions requires making your Physics code more complex and comes with their own trade-offs. The first solution will make the game feel choppy, but still move at the same speed, with the potential problem of getting really bad lag if the physics code is slowing things down. The second solution will make the game move in slow motion whenever there's a lag spike, which would be unacceptable if we're playing an online multiplayer game.
1
u/driver1676 5d ago
In a general sense, decisions are made because they’re considered good enough for their end product. If you make an assumption that your game is going to only be played at 60fps, then you can simplify some internal systems by building them around that assumption.
1
u/cubevato 5d ago edited 5d ago
Suppose you work at a small bagel shop, where you serve only two things: coffee (a single time step of a physics simulation) and bagels (a frame of animation). Every time a customer comes in, they can order a coffee or they can order a bagel or both. If every customer orders a coffee but roughly only every third customer orders a bagel, then you will serve, on average, three times as many coffees as bagels, but this might fluctuate.
Now suppose one day you realize that all these extra coffee sales aren’t really profitable, for whatever reason, and that the time you spend preparing all of the extra coffees could be better spent on other things, like making bagels, so you adjust the menu. Now, every person who comes in can order a coffee with bagel, but they can no longer order coffee or bagels independently. So now the rate of coffee sales and the rate of bagel sales are linked.
0
u/Sightblender 5d ago
Um, I know what everyone is saying is true but its not what I would have thought physics tied to frame rate meant. At least I remember with the original Quake(?) game that if you had a higher FPS the physic calculations would change your character's performance in the game world. Higher frame rate had a more accurate simulation, lower frame rate the simulation was much less precise so both sides would lead to strange behaviors? Is that not what this is?
-1
u/Dysan27 5d ago
It means the time step of the physics engine is set by the frame rate. Usually 1 time step for every frame.
So if you are doing 60 fps every time the physics engine runs it calculates how much things have moved in 1/60th of a second. If you are at 120 fpd, it would calculate how much things have moved the 1/120th of a second.
What this means is that physics can act different at different fps.
-4
u/mr-slickman 5d ago
Something that should work the exact same regardless of performance being tied to performance