0 Favourites

Lerp - I Need Help

  • Hello All,

    <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.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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

    Every tick
        -> 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
157 12,688
megatronx's avatar
megatronx
Unread hot topic
0 Favourites
Kiira will help! :D
132 16,604
Kiira's avatar
Kiira
Unread hot topic
0 Favourites
I need a beta tester (or two)
69 5,947
alspal's avatar
alspal