Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | AALivingMan |
I was following a tutorial on creating cutscenes using a Camera2D and Tween for a topdown 2D game.
I wrote the code posted below for the root node of my Scene, using the tutorial.
I have a Tween node as a child of my Camera.
However, for some reason, Godot does not seem to be able to actually fetch the “Tween” node using the get_child()
method.
Code:
extends Node2D
onready var camera = $Camera
func _ready():
moveCamera(Vector2(400, -250), 2.0)
func moveCamera(targetPos : Vector2, speed : float):
var originalPos = camera.global_position
# Error is here:
camera.get_child("Tween").interpolate_property(camera, "global_position", originalPos, targetPos, (targetPos - originalPos).length() / speed)
Error: Invalid type in function 'get_child' in base 'Camera2D'. Cannot convert argument 1 from String to int.
I’m pretty much stumped on how to fix this. It looks like it’s trying to convert the name of the Tween node into an integer, but I’m not sure why.