Lerp or Set Position

Just started using Construct 2? Post your questions here

Post » Thu Mar 17, 2016 5:38 pm

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:

Code: Select all
Self.Y+(200-Self.Y)/10


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.

Thanks for your advice.
B
24
S
12
G
11
Posts: 260
Reputation: 7,883

Post » Thu Mar 17, 2016 7:28 pm

What ever method you are most comfortable with, so it's up to you.
I would make sure to use dt however.
Image ImageImage
B
168
S
50
G
163
Posts: 8,220
Reputation: 105,059

Post » Thu Mar 17, 2016 7:34 pm

newt wrote: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.
B
24
S
12
G
11
Posts: 260
Reputation: 7,883

Post » Thu Mar 17, 2016 7:45 pm

Dt is a small number, in fact the main point of it is that it can be zero.
Anything times zero=?
Image ImageImage
B
168
S
50
G
163
Posts: 8,220
Reputation: 105,059

Post » Thu Mar 17, 2016 10:24 pm

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)
B
33
S
18
G
27
Posts: 2,435
Reputation: 20,334

Post » Thu Mar 17, 2016 11:19 pm

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.
B
33
S
18
G
27
Posts: 2,435
Reputation: 20,334

Post » Thu Mar 17, 2016 11:23 pm

99Instances2Go wrote: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 :P
B
24
S
12
G
11
Posts: 260
Reputation: 7,883

Post » Fri Mar 18, 2016 8:31 am

You could also use litetween ( behavior-litetween_t70700 ) for stuff like that. I used it in my game and it looks really cool and smooth :D https://www.scirra.com/arcade/action-games/build-6116
B
14
S
2
Posts: 35
Reputation: 789

Post » Fri Mar 18, 2016 2:39 pm

laypax wrote:You could also use litetween ( behavior-litetween_t70700 ) for stuff like that. I used it in my game and it looks really cool and smooth :D https://www.scirra.com/arcade/action-games/build-6116


Thanks! And your game does look smooth, and fun. Good job :)
B
24
S
12
G
11
Posts: 260
Reputation: 7,883

Post » Fri Mar 18, 2016 2:52 pm

Bleenx wrote:
laypax wrote:You could also use litetween ( behavior-litetween_t70700 ) for stuff like that. I used it in my game and it looks really cool and smooth :D https://www.scirra.com/arcade/action-games/build-6116


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


Thanks :oops:
B
14
S
2
Posts: 35
Reputation: 789


Return to Beginner's Questions

Who is online

Users browsing this forum: JaredX and 2 guests