# Expression needed! Maybe i've missed one?

0 favourites
• 4 posts
From the Asset Store
Footsteps SFX One contains 400 sounds of steps and jumps on different surfaces.
• We have lerp - for example: lerp(a, b, c)=d

So if i have a, b, d - how should i calcutate c?

Example: i have a timer that ticks from 3 to 0. When the clock is on 1.5 that expression should return 0.5, when the clock is on 0, the expression should return 1.

Is there already an expression on this? Or maybe you can give me a solution?

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• I apologise - it's 1 - 1/x.

...right?

• Not quite. lerp(a, b, c) = a + c * (b - a) = d

To calculate c from a, b and d, you'd rearrange to solve for c:

a + c * (b - a) = d

c * (b - a) = d - a

c = (d - a) / (b - a)

e.g. if lerp(10, 20, 0.5) = 15

then the other way round, given a = 10, b = 20 and d = 15:

c = (15 - 10) / (20 - 10)

c = 5 / 10

c = 0.5

I'm wondering if an "unlerp" system expression would be a useful addition. So unlerp(a, b, d) would return c, e.g. unlerp(10, 20, 15) = 0.5

• Google said that "unlerp" is already in use in some scripting languages. I think it would be usefull. I vote Yes.

• 4 posts