+1 vote

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

in Engine by (23 points)
edited by

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)

Please log in or register to answer this question.

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 Frequently asked questions and 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 [email protected] with your username.