unlerp

Discussion and feedback on Construct 2

Post » Sun Aug 12, 2012 10:51 pm

Could someone please explain me how it works?

Manual says

[Quote]unlerp(a, b, y) Reverse linear interpolation: if lerp(a, b, x) = y, then unlerp(a, b, y) = x. Calculates (y - a) / (b - a).[/QUOTE]

but to be fair i don't get it.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Sun Aug 12, 2012 11:58 pm

The manual gave the full definition: it calculates (y - a) / (b - a), which is the opposite of lerp. So unlerp(a, b, lerp(a, b, x)) = x. E.g. lerp(10, 20, 0.5) gives 15, so unlerp(10, 20, 15) gives 0.5.Ashley2012-08-12 23:59:42
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Aug 13, 2012 12:10 am

Yes, that part of manual I can understand ;P

Let me rephrase my question. What about practical use of unlerp

I can easily comprehend what e.g. lerp(self.x,target.x,dt) do, but unlerp?

I know i'm missing something simple.
ImageImageImageImage
B
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Mon Aug 13, 2012 3:59 am

One possible use of unlerp is to do scrollbar math.
http://dl.dropbox.com/u/5426011/examples13/unlerp_scroll.capx
B
79
S
24
G
54
Posts: 4,747
Reputation: 40,757

Post » Mon Aug 13, 2012 8:45 am

In layman's terms, it gives you the percentage of point between two values.

You have points A and B and you want to know where your "x" between points is in relation to those points. So you do unlerp(A,B,x) to see where the x is standing relative to the range between A and B.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Tue Jun 11, 2013 9:55 pm

Thanks for the examples of using unlerp guys! It's SUPER useful stuff.
B
13
S
3
G
4
Posts: 19
Reputation: 3,081


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 8 guests