0 votes

i write this code for grid movement.i want know about the code.

func ready():
pass
func _process(delta):
if Input.is
actionjustpressed("ui_up"):
position.y -= 10

what is position.y?
I understood that the position is a member variable of node2d.
but i do not know what y is.

i search in class reference.but i could not find y.
how to search y?and what is y?
variable?function?

in Engine by (188 points)

1 Answer

0 votes

Y is from a vector. Position is a Vector2(X,Y) for 2D and by calling position.y you are changing it's Y value.
In short vectors are points on Grids.

This is what a 2D vector looks like:
enter image description here
As you can see if the position is (0,0) and we add 1 to Y. We get an arrow pointing UP.
A vector can represent any rotation:
enter image description here

The awesome thing about vectors is that it keeps both the rotation and direction inside it.
So we can get how far a enemy is and at what angle, by just knowing our own grid position and the enemy position.

Edit:
http://docs.godotengine.org/en/3.0/classes/class_vector2.html

http://docs.godotengine.org/en/3.0/tutorials/math/vector_math.html

by (1,443 points)

thanks for comment.i found x function in vector2.

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.