Problem with lerp()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MOSN

I have this piece of code which is supposed to move the camera:
get_parent().find_node(“MenuCamera”).position.x = lerp(get_parent().find_node(“MenuCamera”).position.x, 995, 0.15)

It runs every frame so as far as I can see the camera should eventually end up at (or very near to) 995. But for some reason i stops at 412. Have used lerp() like this before without problem. Have I messed something up or could it be related to the parent node or something?

What kind of camera is this? A regular Camera? An InterpolatedCamera? Maybe it has subverting to do with the camera type?

Ertain | 2019-12-13 20:40

It’s a Camera2D

MOSN | 2019-12-14 08:36

:bust_in_silhouette: Reply From: SpkingR

I guess:

  1. the process stops before the camera goes to the expected place;
  2. or the camera has the limit set as 412 in x position.
    You can try to print the position of the camera to figure out the problem.

Already tried printing it and none of those two are the case.

MOSN | 2019-12-14 08:36

Maybe the problem is occurred by the camera node settings.
I just test the lerp function with the code x = lerp(x, 995, 0.15) and finally the result is all right.

SpkingR | 2019-12-14 09:36

Whoops I found the problem. I forgot to disable another process on the parent node moving the position.x towards 0, so it was being “dragged” in two directions and 412 just seems to be where it settles.
Thanks anyways :slight_smile:

MOSN | 2019-12-14 17:35