Interpolate diferent values in the same time (lerp)

1 favourites
  • 9 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi.

    I want to interpolate values with lerp using different increments in the same time frame.

    I mean:

    1 must be increased to 3 in a duration of 3 seconds.

    0 must be increased to 5 in a duration of 3 seconds.

    I do not know if I explain myself clearly.

    I need to interpolate different values in the same time frame.

    Interpolation must consume the same time for any value.

    What formula should I use?

  • first do something like this for a timer that goes from 0 to 3 and stops.

    global number t=0

    every tick

    -- set t to min(t+dt, 3)

    then use

    lerp(1,3, t/3)

    lerp(0,5, t/3)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks R0J0 it worked perfect for me.

    :)

  • Hello, R0J0hound... are you here?

    Please could you tell me how I can do it without using lerp ?.

  • lerp(a, b, f) is equivalent to this formula: (a + f * (b - a))

  • But lerp is different in every tick.

    Initially it is faster and then it gets slower (a smaller value).

    I want to keep the same value in each tick.

  • No, lerp does not get faster or slower if a and b values are fixed.

    Add dt to t; Player set x to lerp(100, 500, t) - player will move at constant speed.

    Player set x to lerp(player.x, 500, dt) - will start fast and then slow down.

  • Hi, using the formula you told me:

    Add dt to t; Player set x to lerp (100, 500, t) - player will move at constant speed.

    The value never stops increasing, the value exceeds 500 and continues to increase.

    It does not stop at 500.

    How to make it stop at 500 if the initial value can be 100 or 700 ?, I mean, the initial value can be greater or less than 500.

    Can you make it stop when it reaches 500?

    I think it would be best to use the tween behavior of lunarray

  • You can make it stop by making t stop increasing. Here’s one way to do it.

    Every tick

    — set t to min(t+dt, 1)

    — set x to lerp(50, 500, t)

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