Constant Movement Speed
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
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
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:
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.
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.
November 04, 2000 04:31 AM
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)
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)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement