Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post Posted: October 8th, 2017, 8:11 am 
 

Joined: August 12th, 2017, 3:17 am
Posts: 7
Location: Pakistan
So chili used this code to make the snek gradually speed up. :shock:

Code:
snekMovePeriod = std::max( snekMovePeriod - dt * snekSpeedupFactor,snekMovePeriodMin )


But this code isn't making any sense to me :? and I don't even know what is making it difficult.
I think what is making me annoyed is I can't seem to figure out how long will the snek need to reach its maximum speed and how much speed will snek increase every frame.


P.S. I know its only math but I can fiqured this shit out. :( :x :cry:

P.S.S Thanks chili For Making these awesome tutorials. They have helped me greatly toward taking tangible steps for creating a open world RPG game. :mrgreen: :mrgreen:


Top 
 Profile  
Reply with quote  
 Post Posted: October 8th, 2017, 8:26 am 
 

Joined: August 12th, 2017, 3:17 am
Posts: 7
Location: Pakistan
Code:
snekMovePeriod - dt * snekSpeedupFactor


I fucked around the code and I understood that if we only subtract the snekSpeedupFactor from snekMovePeriod than the snek will reach its maximum speed in only under 1 sec but I can't figure out:
how does multiplying the frameTimer(dt) limit the time snek need to reach its maximum speed?


Top 
 Profile  
Reply with quote  
 Post Posted: October 8th, 2017, 10:17 am 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 487
Location: Idiot from northern Europe
dt is how much time each frame takes.

If you didn't multiply by dt and instead just adjusted snekSpeedUpFactor until you think it looks good, then the speed will be different on different computers depending on their framerate.

say your framerate is 60fps. then dt = 1/60.
say speedupfactor is 10. You're now subtracting 10 * (1/60) from moveperiod every frame. This means that in one second you have subtracted 10 from moveperiod

if instead, your computer runs at 120fps. then dt = 1/120.
You'll be subtracting 10 * (1/120) every frame and once again you'll have subtracted a total of 10 after 1 second

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: October 8th, 2017, 11:08 am 
 

Joined: August 12th, 2017, 3:17 am
Posts: 7
Location: Pakistan
I knew why it was used It just became jumbled in my brain :oops:
Thanks for clearing it up!


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

Board index » Everything


 
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
You cannot post attachments in this forum

Search for: