0 Favourites

Variables and DT

  • 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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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.

  • 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)
Similar Topics Posts Views Last Post
Unread hot topic
87 5,378
facecjf's avatar
facecjf
Unread hot topic
42 5,111
Jayjay's avatar
Jayjay
Unread hot topic
64 12,946
trollface's avatar
trollface