#### Archived

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

# Physics & framerates

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

## Recommended Posts

I've been using a fixed frame rate for my game but I now want to change this so that all the physics are calculated from the time elapsed between each update. I'm just a little confused as to what values to change. At the moment I have a spaceship that is updatedlike this...

#define MASS        1
#define MAXVELOCITY 10
#define MAXTHRUST   5

Spaceship::Update()
{
accel += current_thrust / MASS;

velocity += accel;

velocity.truncate(MAXVELOCITY);

pos += velocity;
}

I have now changed this to:

Spaceship::Update(float time_elapsed)
{
accel += current_thrust / MASS;

velocity += accel * time_elapsed;

velocity.truncate(MAXVELOCITY);

pos += velocity * time_elapsed;
}

Which I think is correct, but I'm now unsure how to adjust the MAXVELOCITY, MAXTHRUST values so that my ship behaves the same as it did with a constant frame rate. Can anyone help? [edited by - jeffB on April 28, 2003 6:23:29 AM]

##### Share on other sites
Spaceship::Update()
{ accel += current_thrust / MASS; velocity += accel; velocity.truncate(MAXVELOCITY); pos += velocity;}

##### Share on other sites
Edit: oops silly random key jabbing

Spaceship::Update()
{
accel += (current_thrust / MASS) * time_elapsed;
velocity += accel * time_elapsed;
velocity.truncate(MAXVELOCITY);
pos += velocity * time_elapsed;
}

In this you multiply values by current time when you want to factor in their current effects. But you want the results of all of your calculations to be time independent. So for instance never store velocity as it was last frame, you should always store it on a per second basis.

[edited by - gleno on April 28, 2003 6:35:27 AM]

• 11
• 20
• 12
• 9
• 34
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999847
×