Archived

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

Wavarian

Constant Movement Speed

Recommended Posts

Wavarian    850
Urgh.. Problems.. I have a timer checking for keypresses every millisecond, and if it detects the up arrow being pressed, it moves the camera forward 2 units. What im getting at is why on some computers it''ll move 2 units/ms, but 3units/ms on others.. shouldnt the timer be restricting the movement to 2 units/ms only? How can i correct this if the damn timer wont do its job?? thanks pplz -- wAVaRiaN

Share this post


Link to post
Share on other sites
zedzeek    529
time how long the last screen took to draw (FPS)
and update the movement based on that ie the quicker the fps the less u wanna move an object each frame


http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Quantum    122
do something like:

DWORD StartFrameTime, TotalFrameTime;

while(1)
{
// Main event loop:
StartFrameTime = GetTickCount();

// Do stuff..
TotalFrameTime = GetTickCount() - StartFrameTime;
}


now, you can move objects based on the TotalFrameTime
so for each object, do something like this:

ObjectX += ObjectXVel * TotalFrameTime;
etc.

ofcourse you might want to divide TotalFrameTime down a bit because its likely to be anywhere between 10 and 100 (in ms)

hope this helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You should get the time at the start of each frame and calculate the delta of time since the last frame, then as Quantum says do

Object.X += Object.X.Vel*deltaFrameTime;

Rather than just timing the frame, you ought to take into account the game loop etc. as well (I think one of the ''Code on the Cob'' articals (#2?) deals with this)

Share this post


Link to post
Share on other sites
oglman    122
Isn''t it because it doesn''t move forward every millisecond it moves forward every cycle. So depending on your video card, prcessor speed, available memory, etc it will move forward at different speeds.




Open mouth, insert foot

Share this post


Link to post
Share on other sites