Variables and DT

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm trying to figure out how add to a Final Score variable so the duration is always the same regardless of the score.

    ie. You beat the level and your score is 12,000, in 2 seconds your Final Score meter will go from 0 to 12,000 increasing by x.

    Currently I'm just using "add 100" to Final Score every tick if Final Score variable =/ Score variable. and then when the final score is over it sets the text to the score variable. Obviously this isn't timed like I want it at all, and I'm having trouble figuring out where to start...

    Any help would be greatly appreciated!

    Thanks.

  • You could lerp it.

    currentscore starts at 0.

    lerp(currentscore,finalscore,10*dt)

    Play around with the 10*dt which is the speed. I believe 60*dt is 1 second.

    It will never quite reach the final score though as lerp slows down as it progresses.

    You'd have to put it in a condition like,

    currentscore<finalscore-1 do lerp

    currentscore>=finalscore-1 set score to final score.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm trying to figure out how add to a Final Score variable so the duration is always the same regardless of the score.

    ie. You beat the level and your score is 12,000, in 2 seconds your Final Score meter will go from 0 to 12,000 increasing by x.

    Currently I'm just using "add 100" to Final Score every tick if Final Score variable =/ Score variable. and then when the final score is over it sets the text to the score variable. Obviously this isn't timed like I want it at all, and I'm having trouble figuring out where to start...

    Any help would be greatly appreciated!

    Thanks.It's pretty easy.

    Forget about all technical background information and just remember this:

    When using dt ("delta time") on every tick, then everything you multiply with dt will result in the exact portion you need in this tick in order to reach the full result after one second.

    You're aiming for two seconds, so you'd need half the score

    6000 * dt => portion for this tick to reach 6000 after 1 second

    Now just add it to a current score variable on every tick, and current score will be 12000 after two seconds.

    on every tick -> add 6000*dt to current

    current = 12000 -> do final score

    If you want to be absolutely sure you can also use min():

    on every tick -> set current to min(current + 6000 * dt, 12000)

    this will prevent raising the score after reaching 12000

    rule: number * dt = amount needed per tick to raise to number within a second

  • tulamide - brilliant! I think I FINALLY understand dt now!

    Thanks to the both of you.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)