How do I Lerp [Reference]

Get help using Construct 2

Post » 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


Image
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Mar 17, 2016 6:22 am

Interesting.. someone need to recreate this in Construct.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226

Post » Thu Mar 17, 2016 8:32 am

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

Code: Select all
Global number t=0
Global number tt=0

Every tick
--- set t to (t+dt)%2

t<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
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » 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.
ImageImage
B
105
S
46
G
23
Posts: 778
Reputation: 22,226


Return to How do I....?

Who is online

Users browsing this forum: David181, evillair, Yahoo [Bot] and 59 guests