<img src="http://www.gamecherry.com/quake.jpg" border="0" />
This is my "screen shake" function. Why doesn't it slowly come to a stop?
Thank you in advance.
Develop games in your browser. Powerful, performant & highly capable.
lerp(a,b,p) = a + (b - a) * p
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
-> set range to max(0,range - 0.5*dt)
-> set xOffset to random(-range,range)
-> set scroll X to xFix + xOffset
This way you just have to change range to trigger the shaking