need help with lerp

Get help using Construct 2

» Thu Mar 28, 2013 10:05 am

I create four buttons on the right side and when i touch button '1' set variable 'slajd' to 1 so when 'slajd' is 1 lerp object to position x and opacity to 100 (all works fine) but i have second condition- when 'slajd' is 2or 3 or4 set lerp to start possition x and set opacity to 0.

When i set 'slajd' to 2,3,4 my lerp behave weird.
Please take a look at my capx

B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

» Thu Mar 28, 2013 3:38 pm

bump
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

» Thu Mar 28, 2013 4:18 pm

Change your lerp(a,b,c) to a-lerp(a,b,c). If you do the math you'll see the pattern. I'm heading out the door at the moment, or I'd spend more time explaining - sorry.
B
67
S
19
G
122
Posts: 3,207
Reputation: 73,401

» Thu Mar 28, 2013 4:54 pm

@blackhornet what do you mean 'a-lerp' ?
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

» Thu Mar 28, 2013 6:28 pm

lerp(a,b,c)

lerp(100,0,.9)

a - lerp(a,b,c)

100 - lerp(100,0,.9)
B
67
S
19
G
122
Posts: 3,207
Reputation: 73,401

» Thu Mar 28, 2013 7:03 pm

@blackhornet can you explain what is differences between?
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

» Thu Mar 28, 2013 11:27 pm

Actually, I've had another look and there's a number of issues here. Lerp isn't the biggest one. Lerp really wants to go from low to high, not high to low, so you need to invert the math, which is why you have to subtract the lerp value from the original. The manual gives the math for lerp. You can try it manually.

The real issue is Wait! Wait seems to cause more trouble than it does good. If I disable all of the waits, things work again. You have to remember that a true condition runs every tick. So for example, slajd=1 was running many times, calling Wait every time, so there are a lot of waits stacked up by the time you press the second button, which means all of those lerps moving the opacity up where still there, fighting with the slajd=2 code which is trying to move it down. That's why everything was jiggling back and forth.

You need to change your code to use timers, which there are many threads on, to get the timed behaviour you are looking for. Here's the changes with all waits turned off for the moment, and the cytometriaprzeplywowa lerp altered. You can see it fades slowly, where all the unchanged ones disappear almost immediately.

Also you should make sure your variables get set to zero along the way. For example, slajd=1 stays running that code forever, until you press some other button. Same for wybrany.

sample (change the ZIP to CAPX).blackhornet2013-03-28 23:35:43
B
67
S
19
G
122
Posts: 3,207
Reputation: 73,401