Preserving speed on lerp

0 favourites
  • 10 posts
From the Asset Store
Have you ever dreamed of playing in a Speedball game or tournament?
  • If I do something like this:

    Set Position of Camera
    X - lerp(Camera.X, TargetX, XLerp*dt)
    Y - lerp(Camera.Y, TargetY, YLerp*dt)[/code:3q9voxjk]
    and I set TargetX and TargetY to Player.X and Player.Y, how would I retain the speed the camera is traveling if I decide to change the targetX and Y to something else so I don't get a jerk movement from the camera?
  • So I think I've figured out that using an updating lerp value (ie Camera.X and Camera.Y) might not be the best approach for this, but any other way doesn't feel smooth enough to me (also tried rex's moveto behavior). Any other suggestions?

  • I am not sure about what you are trying to achieve. The most basic camera movement using lerp is based on the formula lerp(scrollX, player.X, a value between 0 and 1). Why isn't this smooth enough..?

    Here are some examples based on the same principle ... .capx?dl=0

    There is also a camera plus plugin, perhaps it fits more to your needs. Check it out on the plugin section of the forum.

  • eli0s - the camera lerping is all fine and smooth. What happens is when you change targets, you get a "jerk" because the lerp value isn't changing. So I would have to change the lerp value but I'm not sure how to calculate it based on the distance.

    Maybe that helps making things clearer?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hmmm... I don't really get what the problem might be... Perhaps it's a picking problem? The way you choose and alternate between targets might affect the scrolling system. If you post an example of what you want to achieve, perhaps someone might be able to figure out what is going wrong.

  • eli0s - here's a rough example of what's happening.

  • I see what you mean now... What you need is a way to ease the transition from one camera state to an other. I am afraid I can't think of anything in particular that can improve upon your example... I tried the Lite tween Behavior but it doesn't help much in this case: ... .capx?dl=0

    I believe the problem lies in the linear interpolation between the Camera.X/Y position and the Camera.Trigger.X/Y position. You can move around your mouse in circles and the camera Sprite follows smoothly, but when you Overlap the CameraTrigger, the camera jumps towards it in a straight line, and that is what causes the irregular movement. You'll need a way to curve from mouse.X/Y position toward Camera.Trigger.X/Y position, unfortunately, I don't know how to do something like this... <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad">

  • This might help? I never understand how you're supposed to translate this stuff to C2 :T

  • eli0s - Yeah, it's a tough one. My original idea was to change the XLerp and YLerp the second you overlap the trigger, but the question remains; what do you set it to so it's smooth no matter what speed you're at? I looked at your example; it actually is pretty good, but has the opposite problem. Going INTO the trigger is fine, but pulling out is a little "jerky".

    Tokinsom - I thought about something like this, but everytime I look at equations like this, my head literally explodes.

  • My advice would be to create an event driven behaviour for the camera object, so you control every aspect of its movement: acceleration, deceleration, time to pan to x/y, follow offsets etc. Then, if you change the target, the camera just moves like a physics object (as in it accelerates / decelerates, has a max pan speed etc) without any jerky effects. The lerp is ok to start with but I cannot think of an easy way to use it and do what you're asking here. There's also a camera plugin, IIRC, which is pretty excellent....

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