Best option to move with easing (+request)

Get help using Construct 2

Post » Tue Nov 01, 2011 12:00 pm

You can find more about LERP:HERE

Wow, didn't know about the Move To plugin!
I have to start lurking around that section! Thanks Kyatric!gammabeam2011-11-01 12:40:02
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Wed Nov 02, 2011 12:17 pm

Thank you @gammabeam
I can't open the exemple file, because I can't install CC .
Is there a exemple for C2 too ?    
B
21
S
5
G
5
Posts: 163
Reputation: 5,028

Post » Wed Nov 02, 2011 12:33 pm

Lerp is a very simple function
Lerp stands for Linear intERPolation

This function need 3 numbers parameter
lerp(a,b,t)

a and b are whatever number you want
but t goes from 0 to 1 (well it can go under and over but... let's keep things simple)

lerp(a,b,0) returns a
learp(a,b,1) returns b

the values in between 0 and 1 returns a number X between a and b such as X-a = (b-a)*t
so t describe more or less where you are in between a and b

lerp(a,b,0.5) return the middle so a+(b-a)/2

lerp(0,10,0) = 0
lerp(0,10,1) = 10
lerp(0,10,0.5) = 5

the way newt use it with
Code: Select all
sprite set X to lerp(self.X,destination,0.5*dt)
is a little trick
the .X you have in the lerp is the .X you change in the expression
and 0.5*dt is always more or less the same (depending on fps)

so from step to step in the movement, destination-self.X will be shorter and shorter, so the lerp(self.X,destination,0.5*dt) will continue to move the sprite but slower and slower (ease out)

In short the only issue with this technique is that the sprite will takes time to exactly get to destination. Mathematically it should never arrive but thanks to float rounding stuff it will.
Anyway you should not rely too much on
if sprite.X = destination

that's all :D
Last edited by Yann on Sun Sep 14, 2014 11:23 am, edited 2 times in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Wed Nov 02, 2011 1:26 pm

Thank you for your explanation!
B
21
S
5
G
5
Posts: 163
Reputation: 5,028

Post » Tue Nov 22, 2011 7:18 pm

@yann, I somehow missed your explanation of lerp. Thanks for taking the time to explain it so well.
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

Previous

Return to How do I....?

Who is online

Users browsing this forum: Televangelist and 20 guests