Godot Version
godot-4
Accessing the player node to get player position
I am new to Godot and programming and don’t know how to access the player in Game.gd:
extends Node
var inventoryAmount = 0
var inventory = []
var book = preload("res://collectables/book.tscn")
func _input(event):
if event.is_action_pressed("ui_accept"):
var player = get_node("./player") # This does not work
print("Player is: " + str(player)) # Player is: <Object#null>
How do I access the player? I want to find out the player’s position so that when they drop an object, I know where to put it.
Is there a different / better way to do this?
Here is the scene panel, if that is useful:
Thank you!