Constant Movement Speed

Started by
3 comments, last by Wavarian 23 years, 5 months ago
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
Advertisement
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
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.
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)
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

This topic is closed to new replies.

Advertisement