How to make camera follow player only on y-axis and up?

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

I would like the camera to follow the player only in the “up” direction.

Right now the camera is not a child of the player and I’m using a script to change the position of camera every frame:

func _process(delta):
player_pos = $Player.get_position()
	camera_pos.y = player_pos.y

Unfortunately, to me, it doesn’t seem so smooth (even with the smoothing option).

Is using a script really the best way to make the camera follow the player or is there a way how to have the camera as a child of the player?

:bust_in_silhouette: Reply From: whiteshampoo

You can restrict the movement of the Camera2D in the Limit-Section at the Inspector. (limit_left and limit_right)