0 Favourites

Using Lerp up and down

  • I am using lerp to show wind increase every second. I got it working from a small number to a large number of wind speed, but how do I get it to work the same for Big number to small?

    Here is what I have:

    Every Sec:  
    ->Set LERP_SPD=Lerp(Curent_Speed,End_Speed, 0.1)
    ->Set Current_Speed to LERP_SPD
    
    ----->LERP_SPD>End_Speed-0.009:
    --------->Set End_Speed to random(0,10)
    [/code:336gp7xz]
    
    So what it does is look at current wind speed and lerp it to the end_speed in increments of 0.1.  Then when it reaches the end speed (minus 0.009 to kill the wait at it nears the end number) it creates a new speed to lerp to.  BUT if the new end speed is lower than the Lepr_spd, it just jumps to the low number then lerps forward.  I want it to lerp to the low number just as it does to the high number...
  • I don't really know much about the lerp function. In my testing to solve this question, I could not get it to count down either. However, if you know how to count up using it, you also know how to count down simply by subtracting the lerp value (which is counting up) from the old wind value.

    Instead of using the lerp to change from current_wind to new_wind, always count from 0 to abs(new_wind - current_wind) then add or subtract the result from current_wind.

    I am including a capx that shows the above directions set into a single action. The page simply allows you to type in a number to lerp to and shows the change over time from the previous number to the new one in a text object.

    There are 2 items in the action which may need some clarity:

    abs() returns the absolute (non-negative) value of the equation in the parens

    NewWind - CurrentWind > 0 ? 1 : -1 means if the difference in the values is greater than 0 return 1, if not return -1. It is called a ternary operator. Google can tell you more if you want to understand it better.

    I hope this helps and good luck with your project.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Also, when looking back at your code, I noticed this:

    ----->LERP_SPD>End_Speed-0.009:

    This won't work for subtracting because it will happen immediately upon choosing a new value (as long as the value is at least 0.009 less than End_Speed). What you should do is:

    ----->End_Speed - Current_Speed > 0 ? (LERP_SPD>End_Speed - 0.009) : (LERP_SPD<End_Speed + 0.009):

    Again, this will test to see if the new value is higher or lower than the previous value and check the LERP_SPD values accordingly.

    or even easier:

    ----->abs(End_Speed - Current_Speed) <= 0.009

    This will trigger when the difference is less than or equal to 0.009.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)