I am somewhat new to Godot and coding in general so i am quite puzzled by this issue. My game has a bullet that you can fire which I want the player to be able to teleport to. To be able to teleport, I need both the position of the player and the bullet. How might I get the players position onto the bullet’s script. Extra info: to teleport I want the player to click on the bullet to teleport, this is a top down shooter
You can define a class called “Globals” and put it in auto load.
With the click handler on the bullet, the bullet then updates Globals.player_pos.
The player_pos has a setter function, that emits a player_position_changed signal, which is what the player listens to and updates it’s position if it happens.
That works with integer values independent from other nodes but I need the position of player or dagger to be in the global script. I do have a global script but I can’t get the global position of nodes on there
ah, I didn’t see that when I looked through your screenshots.
Another method would be to use signals that carry the positional data instead.
Suppose you have a signal that sends out when you press the ‘swap’ action, that signal can then be sent to the bullet scene containing some arguements, such as the players position.
I myself, am not too well versed in custom signals, so I recomend looking into the docs as well. Good Luck, feel free to ask anymore questions.
Edit:
Through my own testing as well, I made a mock up (as I dont have you full files) of my own player and Global script, and I was able to hold the player position in the Global script. Am I perhaps understanding you wrong?