Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
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:
X=X-300*dt
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
Develop games in your browser. Powerful, performant & highly capable.
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:
X=X-5
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":
t=t+dt
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)
It still doesn't work.... But I'm fine with the LiteTween, for now. Thanks for the help!