How do I use "LERP" to move from one thing to another

0 favourites
  • 2 posts
From the Asset Store
Move Block
$10 USD
Captivating puzzle game. With challenging gameplay, this game will keep you very engaged.
  • I want to move from one box to another box but I want the camera to move slowly and smoothly from one place to another.

    I read some tutorials but they all seemed to lack the exact coding I needed to write in.

    At the moment I have scroll from box to box by "Enableing" and "un-Enableing" their "scroll to" properties which works but it goes straight to the next box in one frame.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I don't have time to cover every detail right now and not on my computer with Construct so I can provide a capx or anything but thought I would try to explain and you can ask questions on what you don't get.

    Lerp(pointA, pointB, position)

    So lerp will move something from pointA to pointB and the position tracks where it is at between pointA and point B. So the position is from 0 to 1, where 0 is equal to exactly point A and 1 is equal to pointB exactly.

    I have seen two methods implemented

    -every tick

    --set x to lerp(viewport.x, pointB, 0.02)

    So this will calculate the distance between where viewport is currently and point B and move it 2% of the distance. The distance is new every time since viewport.x is constantly changing. Therefore the movement will start out fast and slow down near the end. (maybe never reaching the target exactly because the position is never set to 1)

    The other way, lets say you are moving from 500 to 2000

    Global variable position = 0

    -every tick

    --set x to lerp(500, 2000, position)

    --add 1/60 to position (so maybe about a second, you may want to make this frame-rate independent)

    So this will be a smooth movement as you are moving the same distance every tick.

    So the second version I would to this:

    Global variables






    Group (start disabled)

    -every tick

    --set x to lerp(StartX, FinishX, position)

    --set y to lerp(StartY, FinishY, position)

    --add (how fast you want it to go) to Position

    --If Position >= 1

    ---Group Disabled & set Postion to 0

    Function Camera move

    --Set all the Global variables

    --enable Group

    Hope that is a good starting point for you!

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