# How to make Time Based Updates

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

## Recommended Posts

Hi Everyone,

I'd like to understand how to make time based updates in my game, instead of changing variables every time I work and run from a different computer.

So if I have these input controls, how would I go about it:

GLfloat MoveFactor = 0.01f; //0.05f //0.01f (As you can Tell I have different values for different computers)

if (keys[VK_UP])
{

MoveForward = true;
/*if (walkbiasangle >= 359.0f)
{
walkbiasangle = 0.0f;
}
else
{
walkbiasangle+= 10;
}
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;*/
}
else
MoveForward = false;

if (keys[VK_DOWN])
{

MoveBackward = true;
/*if (walkbiasangle <= 1.0f)
{
walkbiasangle = 359.0f;
}
else
{
walkbiasangle-= 10;
}
walkbias = (float)sin(walkbiasangle * piover180)/20.0f;*/
}
else
MoveBackward = false;

How would I go about implementing it ? I use Windows.h, not glWindows.h

Thanks a lot.
Edited by Cydriic

##### Share on other sites

If you got trouble implementing i can share you my code. Just ask.

##### Share on other sites

Really, you want to give your movable objects velocity.  This velocity is just a distance/time.  I would advise starting with pixels/second, since it is the most basic method to work with (when you get more experienced, you can look at creating your own world coordinates and using a generic unit/seconds).

So, when you go to move an object that has, say, 10 pixels/second velocity, you'd take the elapsed time since the last update, say .033 seconds (30 frames per second, on a slow computer), and move the character 10 pixels/s * 0.33s = 0.33 pixels.  After 30 frame updates (which, at .033 seconds per update is 1 second), the character would have moved 10 pixels.

if your computer updates at 120 frames per second, time elapsed since last frame (deltaTime) would be .0083 seconds;  however, after 1 second (120 updates), the object would still have only moved 10 pixels.

void Object::Update(float deltaTime)
{
// set the xPos and yPos based on xVelocityi and yVelocity and time elapsed)
xPos += xVelocity * deltaTime;
yPos += yVelocity * deltaTime;
}


##### Share on other sites

Nice !!!

Great stuff guys, I was able to implement a first little structure that I will enhance progressively\y.

The Article really got me to understand the basics.

BeerNutts, your explanation is great thanks a lot!

Cheers

Edited by Cydriic

1. 1
2. 2
Rutin
19
3. 3
khawk
15
4. 4
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×