Lerping problems

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Dumuz
var b = 0.0

func _process(delta):
	b += delta
	$p1.translation = Vector3().linear_interpolate(Vector3(0,0,5),b)

—Makes the lerp never end, it doesn’t stop at point B

var b = 0.0

func _process(delta):
	b += delta
	$p1.translation = $p1.translation.linear_interpolate(Vector3(0,0,5),b)

—Makes the lerp ease into point B

The docs have ample of examples of their object transitioning from point A to point B with no easing. Just a straight forward lerp and then stopping, using pseudo code like my examples. But mine doesn’t work.

How do I just lerp from point A to point B at a constant pace without it going past point B and without ease? Without having to be locked into using a Tween node.

Please help, I’m stuck on this.

:bust_in_silhouette: Reply From: Mike Trevor

First of all, in order to make sure your vector doesn’t move past point B, you have to make sure b doesn’t go below 0 and above 1, in other words: 0 ≤ b ≤ 1
To limit b, I’d do this:
b = clamp(b + delta, 0, 1)
1| b += delta
2| b = clamp(b, 0, 1).

For the second snippet of code, It is easing because you are lerping and updating constantly $p1.translation. If you don’t want to ease, a in a.linear_interpolate(b,c) must be a another value.
You could do something like this instead:
$p1.translation = $otherpoint.translation.linear_interpolate(Vector3(0,0,5),b)

Your last example is pretty much my first one. In which case, it’s seems clamping b is the only work around.
I just I was just expecting, verbatim, to be able to do what the docs are doing with essentially a copy and past of their code.

Thank you for the work around, clamping b is definitely the fix!

Dumuz | 2020-04-01 13:51