How do I gradually increase a numeric variable?

0 favourites
  • 8 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • Hello! I would gradually increase a numeric variable... I have a numeric Global Variable, for example equal to -300, and I want it after an event becomes equal to -600. Can I gradually pass from -300 to -600 in one second? I don't understand the lerp expression...

    Thank you very much!!!

  • If you need to change from -300 to -600, that's actually decreasing

    Try this:


    This should decrease X by 300 every second.

    To stop after 1 second, you can either set a condition "If X>-600" or add Clamp() or Max() expression, for example:

    X=Max(-600, (X-300*dt))

    If you want easing effects (speeding up/down etc), you can install LiteTween behavior.

  • You're right sorry, the variable decreases!

    I thought there was something easier

    Meanwhile I try with your suggestions, thanks a lot. If you also have other ideas, write

  • I think I've succeeded with LiteTween!

  • LiteTween is an overkill for this task if you just need a linear change.

    X=X-300*dt is the easiest formula

    If you don't care about it taking precisely 1 second, you can simply subtract 5 every tick:


    At 60fps it would take approximately 1 second to decrease by 300.

    You can do this with lerp if you want, but you will need another variable "t":


    X=lerp(-300, -600, t)

  • Yes, at the beginning I tried with lerp expression.

    But I don't understand the third value and therefore it didn't work.

    I wrote:

    Set X to lerp(-300,-600,0.5*dt), but the value changes immediately.

    Same thing with:

    lerp(-300,-600,1-0.25^ dt)

  • "dt" is frame duration and at 60fps it's always approximately 0.016

    That's why your formula always returns the same result.

    You can try this:

    X=lerp(X, -600, 0.5*dt)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It still doesn't work.... But I'm fine with the LiteTween, for now. Thanks for the help!

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