How do I LERP with dt

0 favourites
  • 11 posts
  • i understand how to use lerp for the classic energy bar.

    its very useful and seems like a way of creating a linear relationship between to changing values

    what i dont understand is how come if i move an object like sprite2 for example with lerp using dt

    that it suddenly turns into an ease out effect...i.e. non linear

    so if i have sprite2.X=lerp(1,800,dt) i get a cool ease out effect...its great but i dont understand why its happening

    i watch dt and its a constant value (more or less)

    can someone explain this to me

    also one more thing...that cool animation effect works great on every tick

    but im having trouble initiating it on a click unless the mouse is held down to create a time event

    ive tried powering it with a loop but that doesnt work

    id like to be using this to lift up platforms at specific times as the player approaches for example. anyone have a trick to make that work

    many thanks

  • lerp(1,800,dt) does not create an easing effect but will vibrate near at value 1.

  • oops sorry...i mean this

    lerp(self.X,800,dt)

    that eases out...but why?

  • ahh...is it because the self.x is changing..so its not a static number as previously which caused the jitter so dt is mulitplying against a changing number causing the ease out

  • still...i dont think it would be an ease out unless dt is somehow getting modified by the position of self...

    heres my file..pretty simple...nice ease out...lol how the hell does that work

  • lol no links and no attachment button..great

  • It's easy mate:

    dt might change slightly, but it's roughly 1/60.

    Each time you do that lerp expression, you move about 1/60 of the distance between those two "points". Each time you move closer means the distance between the two points will get smaller. So you move 1/60 of the smaller value the next time. This results in the movement continuing to get slower, while you never actually reach the destination (it's a bit similar to "Achilles and the tortoise").

    If you wanna do linear interpolation between two points with lerp, you need three instance variables: starttime, startvalue and duration.

    Then do a:

    start movement: set sprite.starttime = time; set sprite.startx = sprite.x

    set duration = 2

    sprite.starttime + duration >= time-dt: set sprite.x to lerp(sprite.startx, 800, clamp((time - sprite.starttime) / sprite.duration, 0, 1))

  • hey thanks for taking the time to responds. i seem to be having conceptual difficulties.

    so i've created a sprite and given it 3 instance variables as suggested -starttime, startvalue and duration

    so now my actions looks like this

    Mouse| On Left button Clicked on Sprite

    |Sprite Set starttime to time

    |Sprite Set startvalue to self.x

    |Sprite Set X to lerp(sprite.startvalue,800,clamp((time-self.starttime)/sprite.duration,0,1))

    i think its almost there. i put in a text field on tick to read out the lerp and when i click, the lerp is generating numbers between 100 and 800. if i can get it as a percentage maybe it will work

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I wrote a whole blog post on using lerp with delta-time.

  • I usually prefer mindfaQ method of using a start value and end value, interpolated with an ever increasing factor that goes from 0 to 1 based on elapsed time / duration.

    Here's a capx demo.

  • the mindfaQ is good in that i understand it and generally is what im trying to do.... on the other hand it seems to have lost the all important easing out which was a nice effect

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