Camera2D not following parent Node2D

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

Hello guys,

following hierachy:
CanvasLayer (with script), child is a Node2D with Camera2D as its child. The camera is set to current but does not follow the Node2D which position is manipulated in teh script. All other Camera2D setting are default.
Additional Info: Pressing play not even centers the camera on the Node2D object.
PS: I would like to insert a screenshot but somehow this is not possible.


Add to “image”
example: google drive

ramazan | 2022-03-24 09:48

Thank you, but this doesn’t really help.
Even if it shouldn’ be nessecary to do this; i added this to my script:

onready var cam = $Camera2D
onready var cursor = $Cursor
func _process(delta):
cam.position.y = cursor.position.y

but it did not change anything.

ErdnussMaus | 2022-03-24 12:12

your code is working. Is there something in the background?

ramazan | 2022-03-24 12:50

here is everything:
Unbenannt hosted at ImgBB — ImgBB
i do not understand why the camera is not following the cursor.

ErdnussMaus | 2022-03-24 12:59

You are quite right. I think there is a place we missed.

You don’t even need it like you said.
func _process(delta):
cam.position.y = cursor.position.y

ramazan | 2022-03-24 13:14

:bust_in_silhouette: Reply From: ErdnussMaus

The root node here must not be a CanvasLayer, it has no transform. Changing it to Control solved it for me.