Lerp or Set Position

0 favourites
  • 10 posts
From the Asset Store
10 Beautiful Pokemon-like Building Pixel Art Sprite Sets
  • 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.
    
    Thanks for your advice.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 ( behavior-litetween_t70700 ) for stuff like that. I used it in my game and it looks really cool and smooth <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> https://www.scirra.com/arcade/action-games/build-6116

  • 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 <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> https://www.scirra.com/arcade/action-games/build-6116

    Thanks! And your game does look smooth, and fun. Good job <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • > 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 <img src="{SMILIES_PATH}/icon_e_biggrin.gif" alt=":D" title="Very Happy"> https://www.scirra.com/arcade/action-games/build-6116

    >

    Thanks! And your game does look smooth, and fun. Good job <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    Thanks <img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarrassed">

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