lerp Clarification

Discussion and feedback on Construct 2

Post » Fri Mar 02, 2012 8:59 pm

How do i...
I have sprite, when i press and hold for example 'q' my sprite smoothly increased two times but no more?
B
93
S
19
G
34
Posts: 1,840
Reputation: 27,963

Post » Sun Mar 25, 2012 8:08 pm

increased two times in size? @delgado

also @animmaniac, I guess I just replied to this thread last time without reading other replies, cuz I didn't see that graphic last time. it really does look great/tutorial material
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Thu Apr 05, 2012 6:43 pm

[QUOTE=Animmaniac]

If you want a constant rate you need to set constant values to the range and increment the ratio every tick. So you need to do something like:

+Every Tick
>set width to lerp(0,600,variable)
>set variable to clamp( variable + dt / duration ,0,1)

Being 'duration' the desired time in seconds to go from 0 to 600. Which means that if duration=2 the width of the object will go from 0 to 600 in 2 seconds.

The clamp expression is used to ensure that the variable value will always stay between 0 and 1, otherwise the width of the object would increase forever.[/QUOTE]


I have been studying in the manual and forum posts about the lerp function. I understand it much better now and want to thank those that have helped the new Construct 2 learners like me. I now can use lerp function effectively in my project. Yet, I was wanting to make my movements and scaling actions work at a constant rate and found the very helpful post by Animmaniac regarding this issue.

I applied the clamp( variable + dt / duration ,0,1) function to accomplish this task, but it did not cause the animation 2 seconds to complete as stated. I tested several options and found that the divided by operator "/" in the formula

"clamp( variable + dt / duration ,0,1)"

did not cause the scaling over 2 seconds as stated.
However, when I changed it to exponential "^" operator

"clamp( variable + dt ^ duration ,0,1)"

and it worked correctly. I am not sure why it works and the original "/" does not, but now my lerp move and scale actions now work at a constant rate. I hope my post does not confuse anyone if I am wrong in my approach to getting this to work the way I need it to.
B
61
S
9
G
8
Posts: 24
Reputation: 8,437

Post » Thu Apr 05, 2012 7:12 pm

Well I have to take everything I stated above back. I does not work with any other values because they grow exponentially and make it slow down to much. Back to the drawing board or Construct 2 animation manual. All I want is to control an animations rate of change over a fixed time frame of my choosing. If I enter 1, 2, or 3 seconds for the time frame that is what I want. Why is that so hard. Clamp is the answer, but it does not function with any consistency. Is it the min, max values that need to be set differently for different time frames?
B
61
S
9
G
8
Posts: 24
Reputation: 8,437

Post » Thu Apr 05, 2012 8:50 pm

Alright, I really feel dumb. My first post and I make a novice gaff and make the simple hard. My problem was I used a global variable in the clamp function that I did not reset. This caused the next clamp function to not start at 0 but at the last value it ended at. So the lesson is "Make sure you track your variables because if you don't you will get variable results.

Sorry Animmaniac for not trusting your expertise!
B
61
S
9
G
8
Posts: 24
Reputation: 8,437

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: saiyadjin and 3 guests