detect when interpolation ends

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lalel345
func _physics_process(delta):
	position.x = lerp(position.x,500,1 * delta)

How do I detect when the node interpolation reaches that position?

when i do this it doesn’t work

if position.x == 500:
:bust_in_silhouette: Reply From: jgodfrey

You’re probably getting bit by your x position never being exactly equal to 500. Try this instead:

if is_equal_approx(position.x, 500):
    print("Lerp done!")

but this method does not work for a vector2 position
how use this for

if is_equal_approx(position, Vecttor2(500,500)):
    print("Lerp done!")

lalel345 | 2020-12-02 15:54

You didn’t ask about a Vector2 in the original question. You were checking a float value (position.x). There is a Vector2 version of this though…

if position.is_equal_approx(Vector2(500,500)):
    print("Lerp done!")

jgodfrey | 2020-12-02 15:59