3 registered members (NewbieZorro, TipmyPip, 1 invisible),
19,045
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Timestep
#381979
09/02/11 21:47
09/02/11 21:47
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
So I've been experimenting a lot recently, just making some prototypes for ideas I have, having some fun. It's all going very well, except for one problem. There's always an issue with something being affected by the framerate, even when time_step is being used. I just made an FPS movement system, and tried out different framerates. You jump higher when the framerate is higher. Confused about why this keeps happening, I did some research on Google, about timestep and all that stuff, and apparently this has been a problem in games for a while, certain things being affected by the framerate. In the Quake games, if you have a lower framerate, you don't jump as high. I was just wondering... is it possible to get around this? I read about there being a variable timestep and a fixed timestep, but don't really understand what the difference is. I assume it has something to do with how certain games slow down everything if the proper framerate isn't being reached, and other games just making everything move more/less every frame if the framerate isn't correct. So, my question is: Is there a way to make my jumping less affected by framerate? I don't want players with an fps of 20 to get stuck on a platforming section or something... Thanks in advance. 
|
|
|
Re: Timestep
[Re: MrGuest]
#381990
09/02/11 23:10
09/02/11 23:10
|
Joined: Dec 2008
Posts: 1,660 North America
Redeemer
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,660
North America
|
The timestep variable is set by getting the arithmetic difference between the current clock time and the clock time of the last frame. Because the time difference between one cycle and another is minute, the FP unit often times cannot accurately record the difference. If your framerate is especially high, the FP unit may record the time difference as 0 and everything in your world will stop. This is one of the many reasons why games are typically locked to 60fps. It completely prevents these apocalyptic scenarios from happening.  Regarding your problem with movement and stuff, though: there isn't any way to totally defeat the problem. But instead of writing this: You could write this:
speed = 16 * max( 1-timestep, 0 );
This tends to return more uniform results. Another trick is to provide a smooth gradient for these time dependent variables. That is, make your "totalspeed" variable something that is only indirectly affected by timestep through velocity, inertia, and friction variables.
Last edited by Redeemer; 09/02/11 23:14.
|
|
|
Re: Timestep
[Re: Redeemer]
#381992
09/02/11 23:29
09/02/11 23:29
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
the FP unit often times cannot accurately record the difference. If your framerate is especially high, the FP unit may record the time difference as 0 and everything in your world will stop. Not true, the clocks inside a x86 PC are accurate enough to get times in the sub millisecond range, otherwise a today OS couldn't work very well. Its also possible to grab the time as double precision floating point from the OS, being valid for about 10k years in the sub millisecond range, subtracting the old time from the current time and converting it to single precision floating point afterwards doesn't really reduce the accuracy by much.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Timestep
[Re: Redeemer]
#382053
09/03/11 19:45
09/03/11 19:45
|
Joined: Mar 2009
Posts: 186
Valdsator
OP
Member
|
OP
Member
Joined: Mar 2009
Posts: 186
|
But instead of writing this: You could write this:
speed = 16 * max( 1-timestep, 0 );
This tends to return more uniform results. I assume you mean: ...but that doesn't seem to work. Jumping in 60 FPS is completely different than jumping in 20 FPS. I tried it in the c_move for jumping, and in the command that decreases the variable "z_move" (which is used in the c_move). Perhaps I'm not using it correctly? Thanks for the help so far. 
|
|
|
Re: Timestep
[Re: Valdsator]
#382060
09/03/11 22:02
09/03/11 22:02
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
The problem is not time_step but the fact that movement per frame is linear, I hope the following sketch explains the problem:  (The result is, of course, the same when you only jump in z-direction.)
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|