hello all; i am having a problem of acceleration after moving to time based movement, instead of frame/pixel movement. before, I had a gradual acceleration such as so:
xVel += 0.5;
if (xVel > 8) xVel = 8;
... //(for each velocity types)
x += xVel;
...//(for each direction/velocity type)
This worked beautifully on a frame based update system, but I found that having varying speeds would mean I'd have to have some objects move 2+ pixels per frame, which after awhile, could look extremely choppy/sloppy. So I moved to time based movement and delta time. From what I understand, I pass the time since last update, and divide it by 1000.f to get it into millisecond format (i think?), and then do something such as so:
x = xVel * (dt / 1000.f);
Unfortunately, this broke the nice "slowly gaining speed" effect my previous, frame based movement I was using. How do I regain said look/feel with this new time based?
Thanks;
Doyle.
delta time acceleration
Should be as simple as adding an acceleration variable based on direction/throttle
i.e.
xVel += xAcc * (dt / 1000)
x += xVel * (dt / 1000)
i.e.
xVel += xAcc * (dt / 1000)
x += xVel * (dt / 1000)
hello all; i am having a problem of acceleration after moving to time based movement, instead of frame/pixel movement. before, I had a gradual acceleration such as so:
xVel += 0.5;
if (xVel > 8) xVel = 8;
... //(for each velocity types)
x += xVel;
...//(for each direction/velocity type)
This worked beautifully on a frame based update system, but I found that having varying speeds would mean I'd have to have some objects move 2+ pixels per frame, which after awhile, could look extremely choppy/sloppy. So I moved to time based movement and delta time. From what I understand, I pass the time since last update, and divide it by 1000.f to get it into millisecond format (i think?), and then do something such as so:
x = xVel * (dt / 1000.f);
Unfortunately, this broke the nice "slowly gaining speed" effect my previous, frame based movement I was using. How do I regain said look/feel with this new time based?
Thanks;
Doyle.
Thanks, Legend.
I'm away from my personal computer, so forgive me for the next silly question:
Would deceleration work as the inverse?
Such as:
xVel -= xAccel * (dt / 1000.f)
and applying that if the right or left arrows are not held.
Is that correct?
I'm away from my personal computer, so forgive me for the next silly question:
Would deceleration work as the inverse?
Such as:
xVel -= xAccel * (dt / 1000.f)
and applying that if the right or left arrows are not held.
Is that correct?
Thanks, Legend.
I'm away from my personal computer, so forgive me for the next silly question:
Would deceleration work as the inverse?
Such as:
xVel -= xAccel * (dt / 1000.f)
and applying that if the right or left arrows are not held.
Is that correct?
Looks about right to me
Edit: make sure abs(xVel) approaches zero so that you don't suddenly start moving in another direction after letting go of an arrow key
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement