2
\$\begingroup\$

I'm implementing a camera for a game and I'm using the LERP formula for smooth chasing. However, if the target moves fast enough, the camera can never reach it unless the t ((1 - t) * v0 + t * v1) value is high enough, but that is exactly the problem: some targets might still move faster than the current t value.

This might lead to 2 problems:

  1. The camera will never reach the object if it's super fast
  2. The camera will very slowly reach the object, depending on its current speed

How do I scale up my t when the delta distance (abs(v1 - v0)) gets lower, so that the camera will starts at a slow chasing rate and increases as it gets closer (therefore no targets could run away)?

\$\endgroup\$
2
  • \$\begingroup\$ I kinda managed to solve this by increasing t over time, as it will eventually reach 1 (guaranteeing to reach the target regardless anything). If there's a better way to doing this, I'm all ears :) \$\endgroup\$
    – Henri
    Jul 18 '20 at 8:38
  • \$\begingroup\$ If you've solved your problem, please share your solution as an Answer below. If you'd like alternative answers, it would help if you clarify whether this chasing is happening continuously, or whether it's triggered on discrete transitions (eg. camera target changes in response to a game event, you have a window of time spent chasing to close the gap, then the accelerating chase behaviour ends and the camera reverts to a different behaviour) \$\endgroup\$
    – DMGregory
    Jul 18 '20 at 11:27
2
\$\begingroup\$

I managed to solve this by increasing t over time, as it will eventually reach 1, on which LERP would return the v1's value, like so:

f = some constant smoothing factor between 0 and 1
t = min(t + f, 1)
v0 = (1 - t) * v0 + t * v1 // lerp

This guarantees to reach v1 even if it's moving, regardless its speed. When moving the camera to a different object, t must be reset for the smoothness effect.

However, if there are any approaches that doesn't require to sum up t every game tick, please leave a comment!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.