Jump to content
  • Advertisement
Sign in to follow this  
evanofsky

Why doesn't timedelta method work?

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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
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
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
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
Hey, you were right tolaris! I was multiplying my velocity by the timedelta, but not the acceleration. Thanks y'all.

Rate++ everyone!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!