[SOLVED]Problems with LERP

0 favourites
  • 7 posts
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Instead of focusing on lerp..

    What is the actual effect you want?

    Could it be achieved by giving a sprite any of the movement behaviours?

  • 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.

  • 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.


    Will try to implement this:

    http ://regentsprep.org/REgents/math/ALGEBRA/AE7/ExpDecayL.htm

  • 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!!!!

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