Movement based on FPS

I don’t want to limit my game to 60 FPS, as I would rather allow the game to refresh the screen faster giving the appearance that it is more smooth. Obviously, however, this means I need to make all my objects movement account for any FPS. More fps = everything moves faster; So how would I create a “coefficient” of sorts that I can use as a multiplier to slow down movement based on fps?

How would this same thing work with gravity, and friction? Friction isn’t really a multiplied effect, and I haven’t gotten that far in my physics class at school.

To make a game work around your current FPS you use something called “delta”.
Delta is the time between frames. There are many good game loops on this forum already, but here’s an outside link:
http://www.koonsolo.com/news/dewitters-gameloop/
This is one that has been recommened before. I’m not an expert on game loops (I lock to 60 fps myself), but start with delta timing.

also for friction and gravity, you need to add velocity, and make a maximum velocity, then accelerate towards this velocity when moving, and then take velocity off at a constant rate. That’s how you model friction. This effect can be ignored when falling, but you need to keep the acceleration while falling as well, as that’s how gravity actually works.

Some say human’s eye can see only 60fps. Others say more makes a difference, small, but it makes it. There is no point in doing what you’re asking to. You can update your game like 120/sec but it will still look almost the same. Probably the same.

I think that the only reason you would do something like you’re asking is if only your game would run extremely slow on some machines. For example, 30ups instead of 60. That would make game update 2 times slower than normal, making it 2x slower than should be. This is when you would need to introduce delta to account for that slowness. There is no point in making it look more smooth than 60 fps. 60fps is very smooth for itself.

Try this thread. It covers various approaches, including Dewitter’s (as mentioned by biznatch) and discusses their pros and cons. The “ideal frame rate” to shoot for in my opinion is the rate that your monitor V-syncs to. No use drawing more than can be displayed by the hardware after all.

Sampling inputs as often as possible is a very good idea.

However there’s little to gain from rendering more frequently than the monitor’s refresh period.

I wouldn’t recommend doing what you’re doing. What’s the point? You’ll just be stressing out the computer with more updates that the eye physically cannot see. If you don’t know how to limit the FPS, then I recommend searching on this forum for game loops, there are plenty. You’ll want to limit the FPS and then move your graphics with delta time, I.E. the time it takes to change frames. This will create the smooth movement you’re talking about, whereas if you were to do it the way you want, you’ll have a wildly fluxuating frame rate that will cause movement to become crazy and your objects will move at different speeds.

If you look at any game, pretty much all of them use a game loop to limit the FPS. Good ones allow you to limit the FPS to a certain rate, like mine can. Others just lock it to 60 FPS. But, like I said earlier, there is no point in rendering frames faster than the refresh rate of your monitor (generally 60 hz), and it’ll just stress your CPU/GPU, which may result in poor performance compared to a game with a game loop with fixed frame rates.

[quote]If you look at any game, pretty much all of them use a game loop to limit the FPS. Good ones allow you to limit the FPS to a certain rate, like mine can. Others just lock it to 60 FPS. But, like I said earlier, there is no point in rendering frames faster than the refresh rate of your monitor (generally 60 hz), and it’ll just stress your CPU/GPU, which may result in poor performance compared to a game with a game loop with fixed frame rates.
[/quote]
I have to disagree though… Almost every game I play by default has an uncapped FPS.

Some examples:
-Call of Duty games
-ALL sources games (tf2, l4d, l4d2, css, csgo, gmod, stanley parable, ect)
-Warframe
-Soldier Front 2
-Doom 3
-Payday 2

I believe source games can be capped though. Call of Duty can too. Actually, come to think of it, I’m pretty sure all of those can! It might not be enabled by default, but I’m sure they all have the option.

Right, they do have the option :slight_smile:
But why would they be uncapped by default?

To be honest with you, I have no idea. It was the dev’s choice to do that, not mine!

And really, why uncap it the frame rate? The only reason to leave it uncapped is to show off. “My engine can run at 505 FPS, and your’s can’t! Ha!”. Why render the game more times than it can actually be displayed? Its just a poor choice in my mind.

I guess I see your reasoning :slight_smile:

Thanks

I’ll just chip in here with some more information.

At 24 fps, the brain sees the images as something actually moving.
You can go higher than this and make for smoother viewing, but the cap for that isn’t much higher than 24, and will be well under 60.

The vast majority of monitors work at 60hz (basically 60fps).
This mean that if your game runs at 300 fps, each time the monitor refreshes, 5 renders would have taken place, 4 of which would’ve just been ignored and waste precious CPU time.

The other way of looking at fps is update speed, but since you’re asking how to keep the update speed constant, you obviously aren’t referring to this.

I agree with HeroesGraveDev and opiop65. I advise you to look at this article about the persistence of vision. Uncapping the frame rate is only interesting for the benchmarks, it has no visual advantage when it goes beyond the frequency of the monitor (it won’t seem smoother), it just wastes CPU/GPU time and energy. Why not capping it by default and giving the option of uncapping it? You should rather take into account the time spent between 2 frames when updating.