Skip to main content
gamedev.net
🔒 Locked

Time based movement

Started by g7tommyB 6 replies 1.2k views
Original Post
g7tommyB
g7tommyB
Hi All, I am implementing time based movement for my spaceship and the formula that I have been using is the following: NewXPos += sin(angle) * time_difference_between_frames * scaler_constant; Similarly for Y position, I have: NewYPos += cos(angle) * time_difference_between_frames * scaler_constant; I do not want to turn Vsync off because it causes image tearing and I can notice missed frames due to vsync being off. When I am testing the spaceship in a partial window, I am getting about 84FPS. When I enlarge the window to full, my FPS immediately drop to around 55. I know this is probably caused by vsync being on. However, the spaceship also flies&turns much slower with the window being full-sized. I thought that my time based movement on the spaceship would compensate for the window being enlarged. Am I completely off on this? What would be the best way to achieve similar speeds in both partial and full windows without actually turning VSync off? Do you guys also believe that turning vsync off is pretty bad, because it does cause frames rendered being missed, which causes "funky" visual effects? Finally, my last question is: Did I at least get the time-based movement right? Thanks a bunch guys, TommyB
g7tommyB
g7tommyB
g7tommyB
I use the clock() call to get the absolute system time and then I calculate the difference in time in my UpdateShipPosition function. The UpdateShipPosition function is called once per frame and the calculation of time delta is performed with respect to the last time the function was called.
I believe this should take care of calculating the time delta between frames...

TommyB
g7tommyB
zedzeek
zedzeek
>> When I enlarge the window to full, my FPS immediately drop to around 55. I know this is probably caused by vsync being on.<<

no its caused by the card having to draw more pixels, ie vsyn has nothing to do with it.

is this >>time_difference_between_frames<< value correct? i mean are u sure this is what u want.

personally though i dropped timebased movement for a fixed time loop for all movement/physics etc, much easier + cleaner.
perhaps worthwhile checking it out?

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
zedzeek
zedzeek
2/ yes for me it doesnt look bad, let the user choose

3/http://www.flipcode.com/cgi-bin/msg.cgi?showThread=Tip-MainLoopTimeSteps&forum=totd&id=-1

http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Brad789
Brad789
Personally I use time base movement and wouldn''t suggest anything else. One of the problems I see with your code, I assume, is that your angle changes are probably frame based. You''re incrementing the angle variable when a key is pressed, by a constand value? In a game I''m making, when a key is pressed I do this(errr, basically):

if (leftArrow)
angle -= timeExpiredBetweenFrames * TURN_CONSTANT;
if (rightArrow)
angle += timeExpiredBetweenFrames * TURN_CONSTANT;

Hope this helps, if everything isn''t fixed maybe you can post more code and I''ll be able to say more.
g7tommyB
g7tommyB
Zedzeek,

I checked out the space-ship game link that you posted and it does look quite amazing. I am wondering, how long it has taken you and how long are you involved with computer graphics. Also, is this game available for download or are you selling it. It sure does look very professional. I will check out the FlipCode thread link that you posted.

Brad,
My angle changes are getting incremented in the exact same way that yours are

Peace,

TommyB
g7tommyB

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.