Could someone please help me? How can I set the value of Vector2 to the global position of a node that is neither a parent nor a child of the node to which the Script was attached?

Godot Version

Godot 4.2.1

Question

How can I set the value of Vector2 to the global position of a node that is neither a parent nor a child of the node to which the Script was attached? I’m sorry if this question is too simple, but I started using Godot a short time ago.

Captura de tela 2024-04-23 173613

I use this vector for the navigation system, I need this vector to be equivalent to the character’s position

You can access other nodes by using NodePath.
See NodePath — Godot Engine (stable) documentation in English
For example in the scene tree

- ScriptNode
  - DirectChild
    - DescendantNode

you want to access DescendantNode from a script in ScriptNode, then you can get that node and its global position by:

var target_node = $DirectChild/DescendantNode
var pos: Vector2 = target_node.global_position

It didn’t work, but I managed to find another way to do what I needed