How do I LERP with dt

Get help using Construct 2

Post » Sun Apr 19, 2015 12:52 pm

i understand how to use lerp for the classic energy bar.

its very useful and seems like a way of creating a linear relationship between to changing values

what i dont understand is how come if i move an object like sprite2 for example with lerp using dt
that it suddenly turns into an ease out effect...i.e. non linear

so if i have sprite2.X=lerp(1,800,dt) i get a cool ease out effect...its great but i dont understand why its happening

i watch dt and its a constant value (more or less)

can someone explain this to me

also one more thing...that cool animation effect works great on every tick

but im having trouble initiating it on a click unless the mouse is held down to create a time event

ive tried powering it with a loop but that doesnt work

id like to be using this to lift up platforms at specific times as the player approaches for example. anyone have a trick to make that work

many thanks
Last edited by blade33ru on Sun Apr 19, 2015 12:59 pm, edited 1 time in total.
B
6
S
1
Posts: 23
Reputation: 427

Post » Sun Apr 19, 2015 12:56 pm

lerp(1,800,dt) does not create an easing effect but will vibrate near at value 1.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sun Apr 19, 2015 1:32 pm

oops sorry...i mean this
lerp(self.X,800,dt)

that eases out...but why?
B
6
S
1
Posts: 23
Reputation: 427

Post » Sun Apr 19, 2015 1:35 pm

ahh...is it because the self.x is changing..so its not a static number as previously which caused the jitter so dt is mulitplying against a changing number causing the ease out
B
6
S
1
Posts: 23
Reputation: 427

Post » Sun Apr 19, 2015 2:04 pm

Message: blade33ru is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
still...i dont think it would be an ease out unless dt is somehow getting modified by the position of self...

heres my file..pretty simple...nice ease out...lol how the hell does that work
B
6
S
1
Posts: 23
Reputation: 427

Post » Sun Apr 19, 2015 2:17 pm

lol no links and no attachment button..great
B
6
S
1
Posts: 23
Reputation: 427

Post » Sun Apr 19, 2015 2:39 pm

It's easy mate:
dt might change slightly, but it's roughly 1/60.

Each time you do that lerp expression, you move about 1/60 of the distance between those two "points". Each time you move closer means the distance between the two points will get smaller. So you move 1/60 of the smaller value the next time. This results in the movement continuing to get slower, while you never actually reach the destination (it's a bit similar to "Achilles and the tortoise").

If you wanna do linear interpolation between two points with lerp, you need three instance variables: starttime, startvalue and duration.
Then do a:
start movement: set sprite.starttime = time; set sprite.startx = sprite.x
set duration = 2

sprite.starttime + duration >= time-dt: set sprite.x to lerp(sprite.startx, 800, clamp((time - sprite.starttime) / sprite.duration, 0, 1))
Last edited by mindfaQ on Mon Apr 20, 2015 6:00 pm, edited 1 time in total.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Mon Apr 20, 2015 12:05 pm

hey thanks for taking the time to responds. i seem to be having conceptual difficulties.

so i've created a sprite and given it 3 instance variables as suggested -starttime, startvalue and duration

so now my actions looks like this

Mouse| On Left button Clicked on Sprite

|Sprite Set starttime to time
|Sprite Set startvalue to self.x
|Sprite Set X to lerp(sprite.startvalue,800,clamp((time-self.starttime)/sprite.duration,0,1))


i think its almost there. i put in a text field on tick to read out the lerp and when i click, the lerp is generating numbers between 100 and 800. if i can get it as a percentage maybe it will work
B
6
S
1
Posts: 23
Reputation: 427

Post » Mon Apr 20, 2015 5:33 pm

I wrote a whole blog post on using lerp with delta-time.
Scirra Founder
B
387
S
230
G
88
Posts: 24,251
Reputation: 192,454

Post » Wed Apr 22, 2015 4:46 pm

I usually prefer mindfaQ method of using a start value and end value, interpolated with an ever increasing factor that goes from 0 to 1 based on elapsed time / duration.

Here's a capx demo.
B
67
S
28
G
24
Posts: 970
Reputation: 18,675

Next

Return to How do I....?

Who is online

Users browsing this forum: alextro, ivanski1983 and 9 guests