Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / Time based movement (again)/DBC

Author
Message
bibz1st
22
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 2nd May 2004 18:46 Edited at: 2nd May 2004 18:48
I know its been mentioned before but can someone give me a simple working example of time based movement as opposed to Frames per second, ya know, the sorta thing that plays the same on any spec machine. I have tried to get it working but am struggling
thanx
rob

its for a simple First Person thingy where the only thing moving will be the player/camera
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 2nd May 2004 19:48 Edited at: 2nd May 2004 19:54
in your game loop you add something like:

difference in time beween last loop and this loop
dt# = timer()-ct#

store current time in loop
ct# = timer()

calculates the loop time difference in seconds
ft# = dt# / 1000.0

the time factor 'ft#' should be a varying value at about 0.03 (+-0.01 depending on your computer) and you can use this value to multiply all moving objects in your game (both translational and rotational).

I would not advise using this for a racing game though... to make the factor 'ft#' more stable i normally declare an array, store the 'ft#' values in the array and take a mean once every loop, it stops the jerks you may experience once in a while.

it's better you understand whats going on so you can recreate this code for yourself rather than just copy+paste in your program.

bibz1st
22
Years of Service
User Offline
Joined: 2nd Jan 2003
Location:
Posted: 8th May 2004 14:30
do those variables have to be the first things in the loop and at what point do I put the movement code.
I just wanted something to look at so I could break it down to understand it
thanx
rob

Login to post a reply

Server time is: 2025-05-23 14:31:41
Your offset time is: 2025-05-23 14:31:41