how to know way of movement ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bgegg

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

func _ready():
pass
func _process(delta):
if Input.is_action_just_pressed(“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?

:bust_in_silhouette: Reply From: MysteryGM

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:

thanks for comment.i found x function in vector2.

bgegg | 2018-11-23 09:46