Lerp - I Need Help

Get help using Construct 2

Post » Sat Jan 05, 2013 5:59 am

Hello All,

This is my "screen shake" function. Why doesn't it slowly come to a stop?

Thank you in advance.
Posts: 79
Reputation: 2,267

Post » Sat Jan 05, 2013 12:13 pm

[code]lerp(a,b,p) = a + (b - a) * p[/code]So in short if you imagine a and b being a start and end of a linear path, p is the percentage travelled.
Also dt is the time in second spent between two frames
so dt varies slightly but stay around 0.017 (1/60 fps) so 0.5*dt is more or less constant.
The only thing you really change is scrollVar which is always random.

What you probably want to do is having a fixed point, and a variable offset. The variation would be random, but the range of the randomness would decrease in time.
So it should look like[code]Every tick
    -> set range to max(0,range - 0.5*dt)
    -> set xOffset to random(-range,range)
    -> set scroll X to xFix + xOffset[/code]This way you just have to change range to trigger the shaking
Yann2013-01-05 12:14:54
Posts: 1,488
Reputation: 16,594

Return to How do I....?

Who is online

Users browsing this forum: DangerGames and 32 guests