how to change the camera following node?

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

i’m trying to make a little cut scene in my rpg game. my camera is child of player but for the cut scene i want it to follow an npc for a shot time, here is my simplified version of node tree
enter image description here
how to make the camera follow the npc for a while in gdscript?

:bust_in_silhouette: Reply From: sparkart

The basic way to do this is to remove the child (camera) from the parent (player), then add the child (camera) to the new parent (npc)

1 Like
:bust_in_silhouette: Reply From: andersmmg

I think a good way to do this could be to have more than one camera. Have one that follows the npc and just set that one as the active camera when needed.

:bust_in_silhouette: Reply From: Thakee Nathees

Finally I found a way

  1. make a camera node as a child of game_world (not player)
  2. add the script below
extends Camera2D

var node_to_follow = get_node("../Player")

func _process(delta):
    position = node_to_follow.position

and in another script

func play_cutscene():
    var npc_node    = get_node("../npc")
    camera_node.node_to_follow = npc_node