0 votes
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.

in Engine by (341 points)

1 Answer

+2 votes
Best answer

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

by (189 points)
selected by

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!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.