![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | 1izNoob |
I have a player character and I also have a camera in every level scene; and I am trying to use a remoteTransform node to get the camera to follow the player. I can set the camera with the inspector, but I would like to do this in code so that I don’t have to do the same repetitive task on every level.
What I have so far is this:
I have my Player scene with a RemoteTransform2d node as a child of a kinematic body (which represents the player), the name of the RemoateTransform2D node is ‘RemoteCamera’.
Then I have lots of level scenes, every single one of which has a Camera2D node called ‘PlayerCamera’.
Now, on my player character, I have the following code:
func _ready():
var PlayerCam = get_tree().get_root().find_node("PlayerCamera",true,false)
$RemoteCamera.remote_path = PlayerCam
But when I run the code, I get the error message:
Invalid set index ‘remote_path’ (on base:‘RemoteTransform2D’) with vlaue of type ‘Camera2D’.
I am confused by this, when I drag the camera node from each level into the Remote Path slot in the inspector, it all works fine. Is that one different from setting the remote_path in code?
So many thanks in advance