TransWikia.com

Linear interpolation: reach moving destination regardless its speed

Game Development Asked on November 2, 2021

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)?

One Answer

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!

Answered by Henri on November 2, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP