Using Lerp and TimeDelta to move objects over time

This forum is currently in read-only mode.
  • Ok, I pretty much get Lerp (thanks to some awesome posts covering it) and TimeDelta is easy, but I'm missing something crucial for using them together...

    I basically want to move two objects each a set, but different, distance, over the course of say 1500ms. I've been trying to use lerp and TimeDelta to achieve this, and I can get them to work individually, but I can't seem to synch them up for some reason...

    is lerp the wrong algorithm to use?

    It should be something like...

    //object1.X <> ScrollX//

    set object1. X

        lerp(object1.x, destinationX, x*TimeDelta)

    set ScrollX

        lerp(ScrollX, destinationX, x*TimeDelta)

    How do I change x*TimeDelta for both objects so that no matter how different their X coords are, they'll still end in the same X at the same time?

    Please help?

  • OR is there something that will work something like...

       mathcommand(a, b, x)//change a into b over x ms?//

  • wait... did I just ask for ((b-a)/x)... are you serious...

    ok, before I try it, someone please tell me if what I just asked for is ((b-a/x)!! I hate sucking at math...

  • I guess I could just use that formula at the beginning of the movement to determine the distances/increments per ms and save it to a private variable for each object, and then use those variables as the distance to move each object per tick *TimeDelta... Ok, someone weigh in here, did I just solve my own stupid problem with an equally stupid solution? Or am I WAAAAAAY off, which given my math skill is probably the more likely answer xD

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • //object1.X <> ScrollX//

    set object1. X

        lerp(object1.x, destinationX, x*TimeDelta)

    set ScrollX

        lerp(ScrollX, destinationX, x*TimeDelta)

    How do I change x*TimeDelta for both objects so that no matter how different their X coords are, they'll still end in the same X at the same time?

    Please help?

    Don't think too complicated.

    So you want two objects with different distances to destinationX to reach that point at the same time. lerp is perfect for that, because wherever you start, as soon as the t-value reaches 1, both will be at destinationX. All you need to do is raising the t-value from 0 to 1 over the period of time you want.

    If you want a number to grow over time, you add n * timedelta to it. The maximum value of t is 1.0. How long do you want it last until 1.0 is reached? 'n * timedelta' equals 'amount per second'

    To have it last 2 seconds, you'd add 0.5 * timedelta (2 * 0.5 = 1)

    To have it last 5 seconds, you'd add 0.2 * timedelta (5 * 0.2 = 1)

    etc.

    + some condition

    -> myT = myT + 0.5 * TimeDelta

    -> lerp(object1.x, destinationX, myT)

    -> lerp(ScrollX, destinationX, myT)

    Just make sure, myT isn't raised anymore, after 1.0 is reached.

  • Brilliant lol, thank you so much!! I knew I was missing something!!

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