How to update smoothed Camera2D's position immediately

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

I’m trying to make an infinite level for a platformer game. At the end of level, I update player’s position to the other end, which looks exactly the same, to make it looks infinite.

It works fine with a normal Camera2D. With a smoothed Camera2D, the camera moves to the other end with smoothed animation.

How can I update the camera’s position without affecting the smoothness?

:bust_in_silhouette: Reply From: exuin

Try setting the Camera’s position directly.

It does not work. The camera will animate to the updated position.

timothyqiu | 2021-03-09 11:36

Turn off the smoothness temporarily?

exuin | 2021-03-09 13:54

I’ve tried that too, not working :frowning:

camera.smoothing_enabled = false
camera.position = updated_position
# add yield(get_tree(), "idle_frame") here won't work either
camera.smoothing_enabled = true

timothyqiu | 2021-03-09 13:59

After testing - try duplicating the yield line. It seems to work when there’s two of them for some reason.

exuin | 2021-03-10 05:33

That works
Thank you!

timothyqiu | 2021-03-10 08:52

:bust_in_silhouette: Reply From: AlexSand

Hi,
Late answer, but the function reset_smoothing ( ) seems to do that:

1 Like