Adam's Lair Forum

game development and casual madness
It is currently 2018/12/18, 16:08

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: TimeMult vs LastDelta
PostPosted: 2018/01/07, 23:53 
Newbie
Newbie

Joined: 2018/01/03, 02:53
Posts: 7
Role: Gamer
I am used to calculating speeds for objects using pixels/second.
Example:
I am using a resolution of 800 pixels and I want an object to take 2 seconds to cross the screen, I set it's speed to 400. Then on the update method I do something like:
Code:
Pos = Pos + Speed * deltaTime

Where deltaTime is usually a float which indicates (in seconds) how much time has passed since the last update.

Duality uses TimeMult instead, a multiplier that is 1.0f at 60 FPS and varies accordingly.
Now if I want an object to take 2 seconds to cross a 800 pixels wide screen, I have to convert that into standard frames:
60 * 2 = 120
then calculate the delta for each frame:
800 / 120 = 6.67
So I have to set my speed to 6.67 and do:
Code:
Pos = Pos + Speed * Time.TimeMult


I find all this very unintuitive, because 6.67 does not represent anything to me. Is it just me?
Time.LastDelta seems to represent what I'm looking for (in milliseconds), but it's help text advices against using this value for frame independent calculations. Why is that?


Top
 Profile  
 
PostPosted: 2018/01/08, 09:45 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 880
Location: Italy
Role: Hobbyist
kiel814 wrote:
Time.LastDelta seems to represent what I'm looking for (in milliseconds),

yes it is, go for it!
kiel814 wrote:
but it's help text advices against using this value for frame independent calculations. Why is that?

my guess is that it means that the final calculations are made independently on the number of frames that it takes (i.e. as you said, move 400 pixels/second, idependently if it takes 60 frames or 20 to do so). That or a typo :mrgreen:

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
PostPosted: 2018/01/14, 13:14 
Newbie
Newbie

Joined: 2018/01/03, 02:53
Posts: 7
Role: Gamer
Awesome! Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group