# how to know way of movement ?

Attention Topic was automatically imported from the old Question2Answer platform.

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

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?

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:

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:

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