Lerp - I Need Help

0 favourites
  • 2 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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.

  • Try Construct 3

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

    Try 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)