0 votes

I downloaded godot a week ago I am new but I know that what happens to me is not an error in the code, what happens is that Vector2 does not work for me, I have followed tutorials to move the character using a variable with Vector2 but when I press the key it does not nothing happens, I've been trying to find something wrong for several days but nothing.

I hope someone can help me.

ps: to clarify if it works for me to use move_local to move the character and I also use body nodes, but to do certain actions I need the Vector2

https://ibb.co/8b2HRZm

Godot version 3.2.3
in Engine by (14 points)
edited by

A "vector" is just a number, expressing a 2-dimensional value. You're going to have to be more specific: show the code that you've tried and any error messages, then explain what you're trying to do.

I put the link to the image in the publication, and by the way when executing the code no error appears,when i pressing the assigned keys the character doesn't move

the movespeed variable is only a variable with integer value var movespeed = 500

Have you added the up/down/left/right actions in the Input Map?

This looks a lot like the code from this tutorial in the docs:
https://docs.godotengine.org/en/3.2/tutorials/2d/2d_movement.html

The "Setup" section at the top tells you to add those actions first.

yes, I have reviewed all that, I have even tried different keys but nothing. In print it appears that the position is always kept at zero

have you tried to use the default inputs?

if input.is_action_pressed("ui_left"):
 print("left input works")
if input.is_action_pressed("ui_right"):
 print("right input works")
if input.is_action_pressed("ui_up"):
 print("up input works")
if input.is_action_pressed("ui_down"):
print("down input works")

Try to print something when you press the keys, if input is registered. the issue might have something to do with the movement logic itself rather than input detection.

1 Answer

0 votes
var motion = Vector2() 
func physics_process(delta):
         if Input.is_action_pressed("Up"):
                 motion.y -= 1
         elif Input.is_action_pressed("Down"):
                 motion.y += 1
         else:
                 motion.y = 0
         if Input.is_action_pressed("right")
                 motion.x += 1
         elif Input.is_action_pressed("right")
                 motion.x -= 1
         else:
                 motion.x = 0
         motion = move_and_slide(motion,Vector2(0,-1))

Let me know if this doesn't work

by (380 points)

it worked, really thanks men

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.