Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Timer Based Movement

Author
Message
Syncaidius
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 15th Nov 2009 13:20 Edited at: 15th Nov 2009 14:28
I've seen a lot of posts asking about timer based movement recently, so I decided to post a little snippet that might be (or might not be) useful to a few people.

It allows you to move or rotate objects at a certain speed regardless of what the game FPS is at.



You'll notice that even at your maximum FPS (sync rate 0) the object is still rotated at a speed of 1 DBP unit per second).

While making it I realized theres potential in it for some nice time based effects too, like slow motion. I've made the snippet so you can change the FPS of the object timer seperate from the game timer so you can slow the cube time or speed it up. This is all done using timers.

No extra media is required to run this. Have fun and please let me know what you think.

EDIT:
This should work fine in DBC as well, without any modifications.

gbark
18
Years of Service
User Offline
Joined: 14th Oct 2005
Location: US - Virginia
Posted: 15th Nov 2009 23:47
Excellent job! Timer based movement can sometimes be tricky to get right, but the end result of games that use it are so much better.
Syncaidius
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 16th Nov 2009 21:46 Edited at: 16th Nov 2009 21:46
@gbark:
Thanks.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Dec 2009 14:12
I just tried this and I hate to say it but it did seem to move faster at 200 FPS than 100 FPS...
Syncaidius
19
Years of Service
User Offline
Joined: 22nd Mar 2005
Location: United Kingdom
Posted: 17th Dec 2009 18:37 Edited at: 17th Dec 2009 18:39
@baxslash:
Are you sure you don't mean smoother at 200 FPS?
Reason I ask is because the higher the FPS is, the lower the movement speed of the object is set to, to compensate for the increased FPS.

For me, on both my laptop and desktop it appears to jump more at 10 FPS (increased rotation speed) but still rotates the same over the same period of time as when I tested at uncapped FPS (e.g it still manages to do 1 full rotation after 500ms at 10 FPS and at uncapped FPS).

=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 18th Dec 2009 01:50
I use a different code snippet for timer based movement (one written by spooky), but I had the same issue as above with sync rate set to 0.

I used IanM's hitimer() function to verify that on powerful pc's there was up to a 15% difference compared to a low spec pc, running the same test program.

My solution was to use timer based movement, but with the sync rate set to 60 to stop it running away on insane spec PC's.

It now works fine, but it does seem to defeat the purpose of timer based movement somewhat.

Without Music or Love the world would be a very empty place... Thank god I still have music.. --'-<@
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 18th Dec 2009 10:11 Edited at: 18th Dec 2009 10:12
Quote: "Are you sure you don't mean smoother at 200 FPS?"

No I mean faster. Maybe there is a bigger difference between my two machines but I know what I am looking at. Don't ask me why it happens but it does, sorry.

The code I'm currently using seems to produce the same result but I found it a little easier to understand and impliment.

The difference isn't huge but it is noticeable.

If anyone has any idea why this happens I would love to know as the code I've looked at and implimented (including this code) looks like it should work!

EDIT: I'll take a look at the IanM's hittimer function and see if that helps...
Binario
14
Years of Service
User Offline
Joined: 19th Jan 2010
Location: @ front of PC
Posted: 23rd Jan 2010 23:15
Syncaidius , just wondering, if a similar snippet like this might be possible of doing, or if its theres any around, searched but havent found anything for DarkGDK?

Login to post a reply

Server time is: 2024-04-26 20:27:36
Your offset time is: 2024-04-26 20:27:36