How to get Camera2D to smoothly transition to a different node?

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

I have a KinematicBody2D node with a Camera2D child. When I press a button, I want the camera to smoothly pan over to another node.

I thought I could achieve this by simply swapping which node the camera was a child of. For example, in my Camera2D script, I have:

func change_focus(node):
	get_parent().remove_child(self)
	node.add_child(self)

Unfortunately, this cause a discrete camera jump to the new node. I want the camera to smoothly pan to the new node from the old one.

How do I get the camera to smoothly pan to the new node?

I tried altering my function by manually setting the global_position of the camera to the global_position of the old node, hoping that, because smoothing is enabled, it would pan to the new node, but it didn’t work.