Archived

This topic is now archived and is closed to further replies.

Ayman Najjar

Gravity, Y Velocity and FPS

Recommended Posts

Ayman Najjar    122
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,

Share this post


Link to post
Share on other sites
SoulSpectre    169
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.



Share this post


Link to post
Share on other sites
szinkopa    198
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.

Share this post


Link to post
Share on other sites
hplus0603    11347
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

Share this post


Link to post
Share on other sites