# How do I use the lerp expression to make smooth movement?

Get help using Construct 2

### » Sat May 17, 2014 10:15 pm

Like when a key is pressed. Thanks
B
20
S
4
Posts: 387
Reputation: 2,274

### » Sun May 18, 2014 1:13 am

Can you be more specific? The lerp takes 3 values, one as a starting value, an other as an ending value and a third one that determines how much in-between of these two values you will get.

For example: lerp(10, 20, 0) is 10, lerp(10, 20, 1) is 20 and lerp(10, 20, 0.5) is 15. That is of course when you trigger it once. If you triggering the lerp every tick (as when a key is pressed down), you will gradually get the second value and the speed by which it'll get there is determined by the third value. A lerp(10, 20. 0.01) will have a slow transition towards 20, while a lerp(10, 20. 0.9) will reach 20 almost instantly.

Of course there are other ways to move stuff around. Have a look to the moveto behavior (viewtopic.php?t=63156&start=0) and to the Litetween/EaseTween behaviors (https://www.scirra.com/forum/viewtopic.php?t=70700&start=0). These are very useful tools!

And here, in this example you can test the lerp speed in action. Use the mouse wheel to increase/decrease the 3rd value which determines the speed of the lerp.
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

### » Sun May 18, 2014 2:26 am

eli0s wrote:Can you be more specific? The lerp takes 3 values, one as a starting value, an other as an ending value and a third one that determines how much in-between of these two values you will get.

For example: lerp(10, 20, 0) is 10, lerp(10, 20, 1) is 20 and lerp(10, 20, 0.5) is 15. That is of course when you trigger it once. If you triggering the lerp every tick (as when a key is pressed down), you will gradually get the second value and the speed by which it'll get there is determined by the third value. A lerp(10, 20. 0.01) will have a slow transition towards 20, while a lerp(10, 20. 0.9) will reach 20 almost instantly.

Of course there are other ways to move stuff around. Have a look to the moveto behavior (viewtopic.php?t=63156&start=0) and to the Litetween/EaseTween behaviors (https://www.scirra.com/forum/viewtopic.php?t=70700&start=0). These are very useful tools!

And here, in this example you can test the lerp speed in action. Use the mouse wheel to increase/decrease the 3rd value which determines the speed of the lerp.

Awesome example, dude
But I want a way to use the lerp whit 'on key pressed' for example... with a trigger, u know?
How can I achieve that?
Thanks

edit: preferably, I want do this without plugins.. that's why the lerp question.
B
20
S
4
Posts: 387
Reputation: 2,274

### » Sun May 18, 2014 3:02 am

Tell me what you wish to do when the key is pressed. Move an object from point A to point B? Also, please verify, is the key press a trigger that it fires just once, or you will have to hold the key pressed in order to complete the lerp action?
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

### » Sun May 18, 2014 3:54 am

eli0s wrote:Tell me what you wish to do when the key is pressed. Move an object from point A to point B? Also, please verify, is the key press a trigger that it fires just once, or you will have to hold the key pressed in order to complete the lerp action?

I want to trigger just once... the object must move smooth from point A to B.
B
20
S
4
Posts: 387
Reputation: 2,274

### » Sun May 18, 2014 1:05 pm

Here, look at this capx:

lerp(A,B,0.1).capx

Input a number (0-640) into the text field and hit ENTER. The object will move to those values (on it's horizontal axis). The trail is just for cosmetic purposes
You do not have the required permissions to view the files attached to this post.
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

### » Sun May 18, 2014 8:43 pm

eli0s wrote:Here, look at this capx:

lerp(A,B,0.1).capx

Input a number (0-640) into the text field and hit ENTER. The object will move to those values (on it's horizontal axis). The trail is just for cosmetic purposes

Perfect!
Thank you very much, dude
B
20
S
4
Posts: 387
Reputation: 2,274

### » Sun May 18, 2014 9:07 pm

You are welcome!
composer - multimedia artist
www.eli0s.com/en/
B
69
S
27
G
6
Posts: 1,146
Reputation: 10,379

### Who is online

Users browsing this forum: saour and 8 guests