How do I gradually increase a numeric variable?

Just started using Construct 2? Post your questions here

Post » Thu Oct 26, 2017 2:00 pm

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!!!
B
5
S
1
Posts: 20
Reputation: 420

Post » Thu Oct 26, 2017 2:30 pm

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

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
126
Posts: 1,753
Reputation: 67,327

Post » Thu Oct 26, 2017 3:07 pm

You're right sorry, the variable decreases! :lol:
I thought there was something easier :)
Meanwhile I try with your suggestions, thanks a lot. If you also have other ideas, write :)
B
5
S
1
Posts: 20
Reputation: 420

Post » Thu Oct 26, 2017 3:26 pm

I think I've succeeded with LiteTween!
B
5
S
1
Posts: 20
Reputation: 420

Post » Thu Oct 26, 2017 3:27 pm

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)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
126
Posts: 1,753
Reputation: 67,327

Post » Thu Oct 26, 2017 4:05 pm

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)
B
5
S
1
Posts: 20
Reputation: 420

Post » Fri Oct 27, 2017 2:15 am

"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)
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
17
S
9
G
126
Posts: 1,753
Reputation: 67,327

Post » Fri Oct 27, 2017 9:47 am

It still doesn't work.... But I'm fine with the LiteTween, for now. Thanks for the help! :)
B
5
S
1
Posts: 20
Reputation: 420


Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 2 guests