0 votes

I'm trying to get the position of KinematicBody2D and put it in a global variable, how do I do that?

Ps: I use C#, but even with GDscript, can you help me.

sorry for my english!!

Godot version 3.2.3(mono)
in Engine by (27 points)

2 Answers

+1 vote
Best answer

first create a script and write every variable that you want to make global
then go to projects->projects settings-> autoload tab
click the folder icon to browse your script
In the 'node name' write name by which you want to access the script (for example write "global" )
and click Add
now your script is available globally and so the variable inside it.
to access any of the variable write < node name >. < your variable name >
in our case 'node name' is global.

here's a tutorial video if you want: https://youtu.be/ZgaM-42xiZg

by (58 points)
selected by

thanks i'll try to do this. Anything, i come back here.

Eu preciso instanciar o script?
+2 votes

For this you need to create an autoload script(say PlayerVariables) and declare a variable in that (say PlayerPosition) then you can simply access and change that variable for now use this code in your player's script.

PlayerVariables.PlayerPosition = position 

Godot Docs can be found here

by (881 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.