The Z_spatial is looking for the player, correct? Is it being spawned/instanced into the scene dynamically, or is it placed in the scene through the Godot editor?
If the node is placed in the scene through the Godot editor, then I'd suggest exporting a NodePath to get a reference to the player node, and then use that reference when you need the player position. Something like this (untested):
extends Node
export (NodePath) var path_to_player = null
var _player = null
func _ready():
if path_to_player != null:
_player = get_node(path_to_player)
# If the player node extends a Spatial...
print (_player.global_transform.origin)
If the node is spawned in dynamically, then it can be a tad more tricky. What I like to do is have the script that is spawning the node(s) pass a reference to the player when the node(s) is spawned. Something like this (untested):
extends Node
export (NodePath) var path_to_player = null
var _player = null
func _ready():
_player = get_node(path_to_player)
var clone = node_to_spawn.instance()
clone._player = _player
Then you can use _player in the spawned object like normal, though you may want to add some if checks to ensure player is set before trying to use it.
Another way you could handle this is to get the player node directly using the scene root, though it isn't nearly as flexible and easy to use (untested):
extends Node
var _player = null
func _ready():
_player = get_tree().root.get_node("root_node/player")
The issue with this method is that the NodePath used from the root node is scene dependent, making it not nearly as usable across multiple scenes. It also can be a tad harder to setup. It does have the advantage of the node getting the player data itself, as it shouldn't rely on other nodes within the scene to pass a reference to the player.
There are other ways to do it, but the methods I listed above are the ones I most commonly use. Hopefully this helps :smile: