Sign in to follow this  
evanofsky

Why doesn't timedelta method work?

Recommended Posts

evanofsky    2913
I'm using some standard timedelta code to normalize the speed of the game based on the framerate. However, it's not working. If the framerate is 350 fps, I jump about 2 feet. If the framerate is 60 fps, I jump about 20 feet. Strangely, I've used this method in a previous game and it worked fine. Also, note that the timedelta variable is a double, and the format is in seconds. In other words, if it took 3 milliseconds to draw the frame, the timedelta variable would be 0.003. Thanks in advance!

Share this post


Link to post
Share on other sites
leiavoia    960
What do you mean by normalize? If you you are going wicked fast, your movement_per_frame should be small and if you are slogging along @ 30fps then your movements will be greater per frame. If you get a 1fps situation, you ought to hopping clear across the screen every frame. With just raw time-based movement, that's what *should* happen.

You'll have to better explain what you mean by normalizing based on the framerate. I'm not sure i understand.

Share this post


Link to post
Share on other sites
evanofsky    2913
Like this:

double lastTime = (double)timeGetTime();
double currentTime, timeDelta;
while(running) {
currentTime = (double)timeGetTime();
timeDelta = (currentTime - lastTime)*.001;
lastTime = currentTime;
do_frame();
}

Then to move, I just do something like this:

position += velocity * timedelta;

Share this post


Link to post
Share on other sites
Jolle    178
If you're running at 350 fps, you really should have better precision than timeGetTime(). Look up QueryPerformanceCounter.

Share this post


Link to post
Share on other sites
tolaris    288
Quote:
Original post by evanofsky
However, it's not working. If the framerate is 350 fps, I jump about 2 feet. If the framerate is 60 fps, I jump about 20 feet.

It sounds like part of your code might be running on per-frame basis without taking the dTime into account. i.e. if you have the character jump and give them some vertical velocity to execute that jump, and then keep reducing this velocity by constant value on every frame instead of scaling this reduction in accordance with dTime...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this