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

Get help using Construct 2

Post » Wed Jun 22, 2016 3:09 pm

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.
B
6
S
1
Posts: 48
Reputation: 505

Post » Wed Jun 22, 2016 4:56 pm

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
StartX
StartY
FinishX
FinishY
Position

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!
ImageImageImage
B
39
S
22
G
11
Posts: 486
Reputation: 9,913


Return to How do I....?

Who is online

Users browsing this forum: Lancifer, MadSpy and 7 guests