Vector2 doesn't work for me

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

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

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.

kidscancode | 2021-03-17 04:15

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

DKDAZero | 2021-03-17 04:51

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:
2D movement overview — Godot Engine (3.2) documentation in English

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

kidscancode | 2021-03-17 04:54

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

DKDAZero | 2021-03-17 05:04

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.

bloodsign | 2021-03-17 11:33

:bust_in_silhouette: Reply From: Mrpaolosarino
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

it worked, really thanks men

DKDAZero | 2021-03-18 00:53