Player will move left and right via the given code

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By timeofdeath12
:warning: Old Version Published before Godot 3 was released.

Now my character is rotating (facing) the mouse pointer but the problem is when I pressed the (“ui_up”) the character still moves in the same direction as before and not on the direction it is facing now. how can I make it walk towards the mouse (on action pressed)

Edit: that question is already been solved with this code:

if Input.is_action_pressed("ui_up"):
    var character = get_pos()
    var mouse = get_global_mouse_pos()
    var move_vector = mouse - character
    move(move_vector.normalized()*delta *speed ) (*-1 if going down)

My 2nd question is how can I move left and right prior with that code

Well by applying some Vector math you can find the normal vector to the Vector you have right now… using the normal vector (which is 90 degrees of the regular vector in case you didn’t study some vectors) you can move like you move right now.

or you can calculate the vector using +/-90 degrees angle(aka instead of 0 degrees use 90 degrees for left and -90 for right)

rustyStriker | 2017-10-22 18:52