Gravity, Y Velocity and FPS

Started by
4 comments, last by Ayman Najjar 20 years ago
Hello everyone, I''m new to this forums although I visit it regulary ... However, I have problem in synchronizing the gravity with FPS, I tried to search about this in the forums, but couldn''t get what I exactly want (maybe I didn''t use the best keywords).. My problem in other words , let''s say I made gravity 9.81 , yVel = 4, and tested it in 45 FPS, when I test it on higher FPS (eg, using a better graphics card) the gravity would be very high, I figured this when I added jump function.. in 45 FPS it was jumping very well, but in 120 FPS it jumped very low jump and very fast .. So, I thought about two ways to fix this: 1- Limiting FPS , which I don''t know how to do it, but I''ve heared that this is not the best solution 2- Trying to synchronizing the gravity or Y Velocity with the FPS --------------------------------------------- Thank you everyone, Regards,
Advertisement
All velocities and accelerations must be taken in respect to delta time. All you need to do is use a time to capture each time frame, for a single threaded app this is usually done once each frame.
To clarify:
1. Initialise a variable to current time.
2. At the beginning of the next frame at the same place in code capture the time again. Subtract the old time from this time.
3. This is your delta time (amount of time passed). Set the old time to the new time you just captured and repeat these steps.

Use the delta time to calculate your current velocities, distance moved etc.

Limiting your frame rate is not a viable option:
1. Frame rates on other machines will vary.
2. Frame rates in your game will vary from time to time (ie drop below your fixed rate.)
3. It''s just a bad, really really bad, way of solving your problem.



Don''t limit FPS, and don''t syncronize it in that way.
This seems to be a timing problem. Your physical model should be absolute independent from the FPS. Your program should be able to simulate something without displaying it. The physical model should work based on the absolute time, not on the number of displayed frames or so.
So your physical model (gravity, mass, velocity, position etc.) is running, and you display its state with a certain rate. This is the sensible approach in my opinion.
One way of doing it is to measure time, and then change the duration of which gravity affects you based on that time, each step. This won''t necessarily lead to consistent gameplay, though, because of integrator loss (and if you do first order forward-Euler, it''ll let you jump higher at higher frame rates !)

Another way is to measure time elapsed, and step the simulation as many quantas as passed in that time, where you define the quanta (10 ms seems like a good number these days). You can find a better description at http://www.mindcontrol.org/~hplus/graphics/game_loop.html
enum Bool { True, False, FileNotFound };
I just used the average velocity for each frame base on acceleration due to gravity
Why don't alcoholics make good calculus teachers?Because they don't know their limits!Oh come on, Newton wasn't THAT smart...
Hello all,

Thank you very very much for your answers , it was very helpful

Regards

This topic is closed to new replies.

Advertisement