# How do I Lerp [Reference]

Get help using Construct 2

### » Wed Mar 16, 2016 10:00 pm

Not a question, but I came across this and liked it, so I thought I'd share.

Different types of lerp motions and a visualization of the math needed to create them -
http://i.giphy.com/3ornjK3itVx9NZ3WUM.gif

B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

### » Thu Mar 17, 2016 6:22 am

Interesting.. someone need to recreate this in Construct.
B
114
S
51
G
24
Posts: 790
Reputation: 23,480

### » Thu Mar 17, 2016 8:32 am

In the general case you can set it up like this:

Code: Select all
`Global number t=0Global number tt=0Every tick--- set t to (t+dt)%2t<1--- set tt to cubic(0,0.5,0.5,1,t)t>=1--- set tt to cubic(1,0.5,0.5,0,t-1)Every tick--- set X to lerp(A, B, tt)`

t goes from 0 to 2 every two seconds. You can adjust it so it goes at a different speed, or just make it stop at the end.

tt maps t to a curve. There are actually two curve parts. Going toward the target and coming back. The cubic expressions is where you define the shape. Change only the two 0.5 parameters. So for example an ease in/out could look like this:
Set tt to cubic(0, 0, 1, 1, t)
B
94
S
33
G
117
Posts: 5,387
Reputation: 75,335

### » Fri Mar 18, 2016 11:45 am

You're right R0J0, I just need to dig the technique more. Currently I managed to create ease in & out with distance cost calculated and stop precisely.
B
114
S
51
G
24
Posts: 790
Reputation: 23,480