How do I use the lerp expression to make smooth movement?

0 favourites
  • 8 posts
From the Asset Store
Add this awesome sound effects to make your visual novel come to life!
  • Like when a key is pressed. Thanks

  • Can you be more specific? The lerp takes 3 values, one as a starting value, an other as an ending value and a third one that determines how much in-between of these two values you will get.

    For example: lerp(10, 20, 0) is 10, lerp(10, 20, 1) is 20 and lerp(10, 20, 0.5) is 15. That is of course when you trigger it once. If you triggering the lerp every tick (as when a key is pressed down), you will gradually get the second value and the speed by which it'll get there is determined by the third value. A lerp(10, 20. 0.01) will have a slow transition towards 20, while a lerp(10, 20. 0.9) will reach 20 almost instantly.

    Of course there are other ways to move stuff around. Have a look to the moveto behavior () and to the Litetween/EaseTween behaviors (https://www.scirra.com/forum/viewtopic.php?t=70700&start=0). These are very useful tools!

    And here, in this example you can test the lerp speed in action. Use the mouse wheel to increase/decrease the 3rd value which determines the speed of the lerp.

  • Can you be more specific? The lerp takes 3 values, one as a starting value, an other as an ending value and a third one that determines how much in-between of these two values you will get.

    For example: lerp(10, 20, 0) is 10, lerp(10, 20, 1) is 20 and lerp(10, 20, 0.5) is 15. That is of course when you trigger it once. If you triggering the lerp every tick (as when a key is pressed down), you will gradually get the second value and the speed by which it'll get there is determined by the third value. A lerp(10, 20. 0.01) will have a slow transition towards 20, while a lerp(10, 20. 0.9) will reach 20 almost instantly.

    Of course there are other ways to move stuff around. Have a look to the moveto behavior () and to the Litetween/EaseTween behaviors (https://www.scirra.com/forum/viewtopic.php?t=70700&start=0). These are very useful tools!

    And here, in this example you can test the lerp speed in action. Use the mouse wheel to increase/decrease the 3rd value which determines the speed of the lerp.

    Awesome example, dude

    But I want a way to use the lerp whit 'on key pressed' for example... with a trigger, u know?

    How can I achieve that?

    Thanks

    edit: preferably, I want do this without plugins.. that's why the lerp question.

  • Tell me what you wish to do when the key is pressed. Move an object from point A to point B? Also, please verify, is the key press a trigger that it fires just once, or you will have to hold the key pressed in order to complete the lerp action?

  • Tell me what you wish to do when the key is pressed. Move an object from point A to point B? Also, please verify, is the key press a trigger that it fires just once, or you will have to hold the key pressed in order to complete the lerp action?

    I want to trigger just once... the object must move smooth from point A to B.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here, look at this capx:

    [attachment=0:126364sw][/attachment:126364sw]

    Input a number (0-640) into the text field and hit ENTER. The object will move to those values (on it's horizontal axis). The trail is just for cosmetic purposes

  • Here, look at this capx:

    [attachment=0:28pn47nj][/attachment:28pn47nj]

    Input a number (0-640) into the text field and hit ENTER. The object will move to those values (on it's horizontal axis). The trail is just for cosmetic purposes

    Perfect!

    Thank you very much, dude

  • You are welcome!

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