0 Favourites

# Lerp or Set Position

• 10 posts
• Hi all.

I currently have a project in which I'm sliding a top menu bar into position from just outside the top of the layout. The code looks like this:

Self.Y+(200-Self.Y)/10[/code:2bc6jqw8]

That brings the menu bar from just outside the layout to the top of the layout at 200 in the Y position. Though the animation looks smooth, would you use a lerp in this case? And if so, is it better to do that? Also, how would you write it? I'm trying to learn best practices in the beginning to avoid clunky code and such later. I learned that code from a tutorial and use it for all my slide-ins.. but I'm not sure if that's the best or most practical way to do it.

• What ever method you are most comfortable with, so it's up to you.

I would make sure to use dt however.

• What ever method you are most comfortable with, so it's up to you.

I would make sure to use dt however.

Thanks. Would I add the dt where I put 10? I tried to do a similar thing in lerp but it wouldn't work right.

• Dt is a small number, in fact the main point of it is that it can be zero.

Anything times zero=?

• Moving just on the Y, that would be

lerp(startY,endY, f * dt)

startY is the Y at startpoint

endy is the Y at endpoint

f is the speed (something between 50 and 120) in pixels/tick (kinda/sorta)

So lets say, menu sits at y = -100

It has to slide to y = 50

at a speed 60

Set y position menu > lerp(-100,50,60 * dt)

• Personaly, i use physics and an invisible solid. Because it fals so nice. It lands so natural. The code is minimal.

And most of all, it has the 'is sleeping' condition.

• Personaly, i use physics and an invisible solid. Because it fals so nice. It lands so natural. The code is minimal.

And most of all, it has the 'is sleeping' condition.

Hey, thanks a bunch! I'm gonna try all that out and see how it does. There seems to be so many ways to do one thing that it's hard picking one. I guess whichever one works and doesn't bog the system down as much, eh?

Edit: That lerp did the same thing only smoother it seems. Thanks for the help with that. I was messing it all up trying it myself

• You could also use litetween (

• ## Buy Construct 3

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

Construct 3 users don't see these ads
• You could also use litetween (

Thanks! And your game does look smooth, and fun. Good job

• > You could also use litetween (

>

Thanks! And your game does look smooth, and fun. Good job

Thanks

• 10 posts