2D platformers: why physics depends on frame rate?

Super Meat Boy is a sophisticated platformer recently released for the PC, requiring exceptional control and a perfect jump. The physics code in the game depends on the frame rate, which is blocked up to 60 frames per second; this means that if your computer cannot start the game at full speed, the physics will go crazy, as a result of which your character will work more slowly and fall through the ground. In addition, if vsync is turned off, the game runs very quickly.

Can those who have come across 2D game programming explain why the game was encoded in this way? Wouldn't it be better if a physics cycle at a constant speed would be a better solution? (In fact, I think the physics loop is used for parts of the game, as some of the objects continue to move normally regardless of frame rate. On the other hand, your character works exactly [fps / 60] just as fast.)

What bothers me with this implementation is the loss of abstraction between the game engine and graphics, which depends on system things like a monitor, graphics card, and processor. If for any reason your computer cannot handle vsync or cannot start the game at exactly 60 frames per second, it will be awesome. Why does the rendering step affect physics calculations in any way? (Most games currently either slow down the game or skip frames). On the other hand, I understand that the old-school platformers on NES and SNES depended on a fixed frame rate for most of their control and physics. Why is this so, and is it possible to create a patford in this tenant without depending on the frame rate? Is there any need for accuracy if you separate graphics rendering from the rest of the engine?

Thanks, and sorry if the question was confusing.

+7
source share
3 answers

There is no reason why physics should depend on the frame rate, and this is clearly a bad design.

I once tried to understand why people do this. I did a code review for a game written by another team in the company, and I did not see it from the very beginning, but they used a lot of hard code 17 in their code. When I started the game in debug mode with the FPS shown, I saw this, FPS was exactly 17! I look at the code again, and now it’s clear: the programmers suggested that the game will always have a constant frame rate of 17 FPS. If the FPS was more than 17, they fell asleep to make FPS exactly 17. Of course, they did nothing, if the FPS was less than 17, the game just went crazy (for example, when I played 2 FPS and drove the car into the game, the game system warned me: "Too fast! Too fast!").

So, I am writing an email asking why they hardcoded this value and used it in their physical engine, and they replied that in this way they simplify the engine. And I replied again: “Good, but if we run the game on a device that is unable to use 17 FPS, your game engine works very funny, but not as expected. And they said they would fix the problem until the next code review.

After 3 or 4 weeks, I get a new version of the source code, so I was very interested to know what they did with the FPS constant, so the first thing I do is search for the code after 17, and there are only a couple of matches, but one of them doesn’t was what I wanted to see:

final static int FPS = 17;

Thus, they removed all of the hard-coded value 17 from the entire code and instead used the FPS constant. And their motivation: now, if I need to put the game on a device that can only perform 10 FPS, all I need to do is set the constant FPS to 10, and the game will work smoothly.

In conclusion, I'm sorry to write such a long message, but I wanted to emphasize that the only reason someone would do such a thing is poor design.

+7
source

Here is a good explanation of why your timestep should be persistent: http://gafferongames.com/game-physics/fix-your-timestep/

In addition, depending on the physical engine, the system may become unstable when the time reference changes. This is because some of the data that is cached between frames is time-dependent. For example, the initial hunch for an iterative solver (how problems solve it) may be far from being answered. I know this is true for Havok (the physics engine used by many commercial games), but I'm not sure which SMB the engine uses.

An article appeared in the Game Developer Magazine a few months ago, which showed how a jump with the same initial speed, but with different time stamps, was achieved at different maximum heights with different frame rates. There was a joke from the game (Tony Hawk?), Where it was possible to make a certain jump when starting in the NTSC version of the game, but not in the PAL version (since the framers are different). Sorry, I can’t find the problem at the moment, but I can try to dig it out later if you want.

+1
source

They probably needed to make the game quickly enough and decided that they would cover a sufficient user base with the current implementation.

Now it’s not so difficult to redefine independence if you think about it during development, but I believe that they can go down steep holes.

I think this is not necessary, and I have seen it before (in some early game with 3D-hw the same thing was used where the game went faster if you looked at the sky and slower if you looked at the earth).

It just sucks. Think about it to the developers and hope that they will fix it if they can.

0
source

All Articles