How do I set a target for the Interpolated Camera in script?

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

Hello Godot Community,

I want to be able to switch which target an Interpolated Camera has through GDScript. However, I have no clue what I am supposed to type into the set_target() function, nor do I know if this is the function I am supposed to use.

I have tried:

set_target($Auxiliary/Camera/CameraPoint/CameraPoint_Conference)

and

set_target($CameraPoint_Conference)

and

set_target(get_node(“Auxiliary/Camera/CameraPoint/CameraPoint_Conference”))

It either doesn’t set the target, or it says that a String is not an Object type. I don’t know what it means by Object type, or what it wants me to type in for that parameter.

Thank you for helping!

:bust_in_silhouette: Reply From: Dlean Jeans

These work in my project:

$World/Camera.set_target($World/Player)
# or
$World/Camera.target = $World/Player.get_path()

Did you mess something up?

I did mess up something else, alongside this.

First, it report a “null_instance” error because I called nodes that were not “in the game, yet”, so I had to attach the script to a parent object.

Second, set_interpolation_enabled was set to false without me realizing it, so the camera was not even enabled, which made me feel silly haha

Third, (the one you helped with) I did not use the set_target() function correctly. So thank you with that!

I had no clue that doing something so simple as targeting a camera through script could have so many points of error!

ThankYouSoMuch | 2019-07-13 13:19