what is lerp? (2 minute tutorial for the non-math

Post your own tutorials, guides and demos.

» Thu Mar 03, 2011 12:45 am

lerp(a,b,t) is a math function that lets you find a value between two other values
• a is the first value

• b is the second value

• t is a number between 0 and 1 that decides how far between a and b you want the value to be

• 0 is all the way at a

• 1 is all the way at b

• 0.5 is halfway between

to better understand it
try this exe:
experiment with different values for a,b,t until you have a firm grasp of how it works
simply type in values for a and b, and drag the red slider to set values for t
try me!

watch the equation change, and watch the bar at the bottom

lerp can be used for everything from health bars, to color fades, smooth angle changes, to smoothly fading sound effect volume. you can also use it in a loop to set up a bunch of sprites in a neat line. there are endless uses. once you understand what it does, you'll find it comes up often as a useful tool when designing games

if you have any questions about how to do any of the above mentioned, or if lerp simply still doesn't make sense. please ask away

once you have a firm grasp on this, you can easily learn cosp, qerp, and cubic, which are even more awesome
update: here's another tutorial with qarp and cubic=
lerp/qarp/cubic tutorial

math is powerlucid2013-07-13 19:07:31
Spriter Dev
B
84
S
20
G
12
Posts: 3,224
Reputation: 16,254

» Thu Mar 03, 2011 1:30 am

Lerpin angles is a bit complicated, might do an example of that.
lerp(sprite.angle, new angle,x*timedelta)= boo hoo when new angle is greater than 360, or is less than 0.

Also a two node path using lerp versus qarp would be a good example.
B
160
S
48
G
79
Posts: 7,226
Reputation: 60,980

» Thu Mar 03, 2011 7:02 am

Great example. I'd love to see what cosp, qarp, and cubic are capable of hint hint
B
223
S
26
G
13
Posts: 1,768
Reputation: 17,862

» Thu Mar 24, 2011 5:18 am

This is probably the most helpful thing to happen to me in a while... thank you so much!
B
5
S
1
G
2
Posts: 99
Reputation: 1,575

» Tue Mar 29, 2011 3:43 am

Here's a little .cap I made a while ago to implement an aiming system similar to a lot of space sims (in this case, I modeled it after Privateer 2 )
It uses lerp quite a bit. Have fun

[url:26dyl9jf]http://dl.dropbox.com/u/1289341/AimTest.cap[/url:26dyl9jf]
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

» Tue Mar 29, 2011 8:11 am

Very useful!! Thanks Lucid.
B
29
S
14
G
10
Posts: 284
Reputation: 7,017

» Sun Apr 17, 2011 10:01 am

Thanks Lucid, I understand it, just don't think it will be useful for anything. Things like health bars are already easy to do with variables, just subtract/add.
B
4
S
1
G
1
Posts: 63
Reputation: 776

» Sun Apr 17, 2011 10:22 am

Did you have a look at the cap I posted a couple of replies ago?
It uses lerp on both the X and Y coordinates of the aiming reticle to predict where to shoot to guaruntee a hit on any of the enemy objects. I'm pretty sure that functionality is now built into the system object however, but they're essentially the same thing
Although, correct me if I'm wrong, I think I've actually created quadratic interpolation with two sets of lerp in that example?

Lerp is great for extrapolating and predicting things!
Because while the third argument is usually a value between 0 and 1, you can go BEYOND 1 to start predicting where a value will be based on the other 2 values

I may have a twisted take on the whole thing, as I'm no mathmatician, I basically just learnt lerp from playing around with it on Construct!
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

» Sun Apr 17, 2011 10:38 am

[quote="alastair":28mqbtpc]Thanks Lucid, I understand it, just don't think it will be useful for anything. Things like health bars are already easy to do with variables, just subtract/add.[/quote:28mqbtpc]
If you can't see lerp being useful for anything, then you did not understand it. Just a very simple example:
lerp.cap
(click and drag the blue sprites)

Now recreate this without lerp. It's possible, but needs more effort. And this is just a very simple example.
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

» Sun Apr 17, 2011 10:41 am

That's a great example!
B
3
S
2
G
5
Posts: 351
Reputation: 2,377

Next