Cannot access other objects through code

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

I want the camera to point at the ball, I know look_at()function but I cannot get access to the ball to get it’s position. pls help

file download:

I’ve downloaded and it’s empty. Just post the lines where you tried to get ball.

USBashka | 2022-07-15 18:52

:bust_in_silhouette: Reply From: jgodfrey

Since the Camera node and the ball (the RigidBody node) are siblings in the scene tree, and you want to access the ball from the script associated with the camera, this should give you a valid reference to the ball in the (now empty) script.

extends Camera

onready var ball = get_node("../RigidBody")

Then, you can do whatever you want with the ball reference.