# unlerp

Discussion and feedback on Construct 2

### » 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.
B
160
S
69
G
44
Posts: 2,611
Reputation: 36,844

### » 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
414
S
245
G
92
Posts: 25,203
Reputation: 200,347

### » 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.
B
160
S
69
G
44
Posts: 2,611
Reputation: 36,844

### » 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
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### » 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
13
Posts: 1,910
Reputation: 13,685

### » Tue Jun 11, 2013 9:55 pm

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

Return to Construct 2 General

### Who is online

Users browsing this forum: No registered users and 4 guests