# Why doesn't timedelta method work?

This topic is 4976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
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 on other sites
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 on other sites
If you're running at 350 fps, you really should have better precision than timeGetTime(). Look up QueryPerformanceCounter.

##### Share on other sites
Quote:
 Original post by evanofskyHowever, 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 on other sites
you should be using fixed timesteps and handle spillt deltas else you're always bound to get this effect.

##### Share on other sites
Hey, you were right tolaris! I was multiplying my velocity by the timedelta, but not the acceleration. Thanks y'all.

Rate++ everyone!!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634063
• Total Posts
3015309
×