# [SOLVED]Problems with LERP

Get help using Construct 2

### » Mon Nov 30, 2015 6:01 pm

Hi, I have been working on a camera smoothly following a player for the past 2 days trying out different portions of events to no avail.
I am finding that the LERP function along with "scroll to" behavior keeps the camera lagging behind the player, mainly do to the fact that the player is moving, and the "x" value in LERP is too small and thus cannot catch up with the player when he is moving, only does so when he stops.

I was thinking that the "x" value needs to be a value that is exponentially growing from 0 to a value, lets say 0,03 in order to move ahead of the player after a short time while the player is still running, and then stopping ahead of the player at the "b" destination. The thing is I don't know how to implement a formula that would exponentially increase the value (accelerate) then exponentially decrease the value (decelerate).

I have tried nesting a LERP inside a LERP in the place of the "x" value but still cant work it out.

I would appreciate any help I have been pulling hairs lately.
Last edited by Solomon on Tue Dec 01, 2015 1:54 pm, edited 1 time in total.
Brick by brick, stone by stone.
B
58
S
25
G
18
Posts: 273
Reputation: 13,413

### » Mon Nov 30, 2015 6:31 pm

What is the actual effect you want?

Could it be achieved by giving a sprite any of the movement behaviours?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Mon Nov 30, 2015 7:04 pm

I want to have a smooth camera transition effect.
The basic idea is to have a smooth camera, that follows the player, and ""slides" (or eases into and out of) so to speak when the player turns around and then catches up to him and proceeds him 300 pixels. This set of events is to apply to both sides. I am finding 2 difficulties:

1) Once the LERP command is still in motion, transferring this LERP into another LERP creates a hard pull instead of a smooth ease.
2) The camera lags behind the player once he is in motion, instead of proceeding him by 300 pixels. It only does so once he has stopped.
Brick by brick, stone by stone.
B
58
S
25
G
18
Posts: 273
Reputation: 13,413

### » Mon Nov 30, 2015 7:22 pm

I reckon the solution would be to incrementally increase the "x" value (for example from 0 to 0.08), which is the time in which the camera travels from position "a" to position "b".
This would speed up slowly the movement.

Unfortunately I have no idea how to create a formula for this exponential increase, any help would be great.

EDIT:

Will try to implement this:
http ://regentsprep.org/REgents/math/ALGEBRA/AE7/ExpDecayL.htm
Brick by brick, stone by stone.
B
58
S
25
G
18
Posts: 273
Reputation: 13,413

### » Mon Nov 30, 2015 8:59 pm

B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

### » Tue Dec 01, 2015 9:29 am

August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,912

### » Tue Dec 01, 2015 1:54 pm

@newt - thanks for the link to the plugin, but Im trying to use as little plugins as possible in order to learn at least some visual coding.

@RamPackWobble - YES! That is it! I was trying to solve this in a similar manner, but instead of taking into consideration the time that the player is mirrored, I used the a timer that checked for how long the left or right keys were kept being pressed. Also did not quite get there with the a and b destinations as a was set to player.self and b was set to player self+300 for both directions thus cancelling each other out.

Thanks a million!!!!
Brick by brick, stone by stone.
B
58
S
25
G
18
Posts: 273
Reputation: 13,413