Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Neen10do

Getting Jerkyness with TimeDelta

This topic is 5620 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 orignally had my 2d game set up so that the velocities were constant, which could cause the game to go at different rates dependent on the frame rate they got (i didn''t know this was a problem at the time i was writing all of my movement functions etc). so now i implemented something like this: Object.x += Object.Velocity * (TimeDelta/8); when doing something like this... i got jerkiness (note when i did not divide by 8... it went extremely fast) i tested timedelta on my machine... and it was 7 or 8 most of the time (using timGetTime()). do you know why im getting jerkiness, im usuing integers, is this a problem, should i use float? ---------------------- i code therefore i am. Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
Advertisement
you should use floats all the way through the system and only truncate them to Int''s right before you use them.

So Object.x should be a float as well as Object.Velocity

Share this post


Link to post
Share on other sites
Yes, if timedelta and velocity are integers, try casting them to floating point before doing the math

Share this post


Link to post
Share on other sites
i made the x,y,xspeed, and yspeed values all floats, and casted top unsigned long for the bltflast method, and im still getting jerkiness, whats the deal?

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
Read the posts...what they're saying is this: if TimeDelta is an integer, then when your computer does:

TimeDelta / 8, you get an integer return. That is, if timeDelta = 7, then using integer math, 7 / 8 = 0. Aka it thinks no time has passed. When it turns to 8, 8 / 8 = 1.

Your line:
Object.x += Object.Velocity * (TimeDelta/8);

Try:
Object.x += Object.Velocity * ((float)TimeDelta/8);

or

Object.x += (Object.Velocity * TimeDelta) / 8;

edit: removed junk about other integers which neen said were allready floats and I didnt see...hurry up and post stupid gamedev!

[edited by - MaulingMonkey on March 3, 2003 8:44:57 PM]

Share this post


Link to post
Share on other sites
Instead of dividint by 8, try this:

Object.x += Object.Velocity * (TimeDelta*0.02f);

tweak that number until you get the results you desire!

Share this post


Link to post
Share on other sites
what exactly is .02f?

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!

Share this post


Link to post
Share on other sites
It is a modifier, just like your /8

0.02f just says it is a floating point number.

I am assuming that TimeDelta is a float.

multiplying by a modifier is much faster than dividing by one, so it will eliminate your jerkiness.

Share this post


Link to post
Share on other sites
quote:
Original post by Neen10do
what exactly is .02f?

----------------------
i code therefore i am.

Aero DX - Coming to a bored Monitor near you!


Umm... 0.02f is a fancy way of saying 0.02 (why the f, I have never understood...)

oh yeah, and 0.02 = 1/50 if that''s what you mean.
1/8 = 0.125 (exactly) if you want to use that.

If the /8 is an arbitrary number especially for that particular function, I''d suggest one of my methods...however, if you /8 all over the place, I''d suggest a global variable of some sort...

aka:

const float deltaMulti = 0.125;

then:

Object.x += Object.Velocity * (TimeDelta * deltaMulti);

or make it a non-const if you want to tweak it in-program, and/or modifiable for speed.

Share this post


Link to post
Share on other sites
One more thing, you know that time elapsed should be calculated similar to this
float CurrentTime;
float LastTime;
float ElapsedTime;
LastTime=TimeGetTime();


begin loop
CurrentTime=timeGetTime();
TimeElapsed=CurrentTime-LastTime;
LastTime=CurrentTime;

do all your game stuff

end loop

Share this post


Link to post
Share on other sites

  • 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!