#### Archived

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

# velocity and frame rate help

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

## Recommended Posts

how would i make an object with a decreasing velocity move the same distance when the frame rate is not constant? this is something like what i do and it''s not working for me: QueryPerformanceCounter(&bb); velocity.x -= .1f*(bb.QuadPart - aa.QuadPart); if ( b.v.x <= 0) velocity.x = 0; QueryPerformanceCounter(&aa); object.x += velocity.x;

##### Share on other sites
As much as you won''t believe it, this is an application of simple calculus. You take the formula for movement with acceleration (negative acceleration in your case), and integrate it with respect to t (that is, time). You can just plug time into the resulting formula to determine how far you''ve moved.

##### Share on other sites
youngo, I dunno how QueryPerformanceCounter works, because I use timeGetTime(). But basically the formula you want is

velocity += acceleration * deltaTime;

position += velocity * deltaTime;

I get my deltaTime, in seconds, like this:

// during initialization:
baseTime = timeGetTime();

// each frame
FLOAT oldElapsedTime = elapsedTime;
elapsedTime = ( timeGetTime() - baseTime ) * 0.001f;
deltaTime = elapsedTime - oldElapsedTime;

##### Share on other sites
The formula really should be:

temp = acceleration * deltaTime * 0.5f;
velocity += temp;
position += velocity * deltaTime;
velocity += temp;

The formula Eric gave creates some problems.
You really have to first add half of the acceleration to velocity, then add velocity to position and then add the other half of acceleration to velocity.

-Hans

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5

• 18
• 20
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633363
• Total Posts
3011514
• ### Who's Online (See full list)

There are no registered users currently online

×