Can't seem to figure out how the snek speed up in T17 HW

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
Farhan687
Posts: 8
Joined: August 12th, 2017, 3:17 am
Location: Pakistan

Can't seem to figure out how the snek speed up in T17 HW

Post by Farhan687 » October 8th, 2017, 8:11 am

So chili used this code to make the snek gradually speed up. :shock:

Code: Select all

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:

Farhan687
Posts: 8
Joined: August 12th, 2017, 3:17 am
Location: Pakistan

Re: Can't seem to figure out how the snek speed up in T17 HW

Post by Farhan687 » October 8th, 2017, 8:26 am

Code: Select all

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?

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Can't seem to figure out how the snek speed up in T17 HW

Post by Yumtard » October 8th, 2017, 10:17 am

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

Farhan687
Posts: 8
Joined: August 12th, 2017, 3:17 am
Location: Pakistan

Re: Can't seem to figure out how the snek speed up in T17 HW

Post by Farhan687 » October 8th, 2017, 11:08 am

I knew why it was used It just became jumbled in my brain :oops:
Thanks for clearing it up!

Post Reply