Ship lerps to a position smoothly. Want it to leave smoothly too.

0 favourites
  • 4 posts
From the Asset Store
A complete set of graphical user interface (GUI) to build 2D video games. With wood, nature, & jungle theme
  • Hi!

    Quick explanation. An UFO comes carrying the player, so I use lerp to get the UFO into position, drop the player in the ground, then I want it to leave flying up in the air, but lerp only gives the effect of "decceleration", not acceleration.

    I've read about unlerp but have no idea if it may be useful for this or it's a math calculation for other stuff.

    Any help is very welcome :)

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I’m guessing you mean you’re using lerp like this:

    Set x to lerp(self.x, target.x, 0.01)

    That does slow down as it reaches the target. But to ease as it moves away you’ll have to do something different.

    I believe with the move to behavior you can specify the easing function as you move to a point. That would be the simplest solution.

    You can do the same with some math and a few variables. You’ll need the start and end positions and variable to indicate progress. For example this does an ease in and out.

    Var t=0

    Every tick

    — add dt to t

    — set x to cosp(startx, endx, t)

    Another idea is to use a velocity to control the motion. Could be as simple as adding 100*dt to the velocity to accelerate away. Maybe just switch between lerping accelerating away.

    Yet another idea is to do the easing with a damped spring. You’d need the velocity and two variables k and d which control the spring stiffness and damping. Both are in the range of 0 to 1. Fiddle with the values to control motion. Could be useful when the target constantly moves.

    Compare: dt>0

    — ufo: add -k*(self.x-target.x)/dt-d*self.vx to vx

    — set x to self.x+self.vx*dt

  • For this type of tasks I use the Tween behavior.

  • Thanks! You gave me some really good ideas. I'll try a few and see what fits better.

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