Movement_script not functioning

Godot Version

4.4

Question

So I have this function:

I call it in the physics_process() funtion but experience that the direction doesn’t feel an Input I guess which makes direction a Vector2(0,0) → basically making the player movement = 0.
I tested holding down arrow_keys instead of keybord_keys (like W,A,S,D) which had the same problem, except when I held down both it was fixed.

A lot of missing context here that could be the cause:

  1. Is _movement() always called within _physics_process() or is there an if/early return that could cause it to get skipped?
  2. Is value of movement_speed being changed somewhere outside of _movement(), to value of 0 possibly, casuing the resulting velocity to be 0?
  3. Are “left” / “right” / “up” / “down” correctly asigned in the input map?

Hard to tell by just this small bit of code - I don’t think there is something directly wrong with it. Gut feeling tells me that if it works when both (arrows and wasd) inputs are pressed, then option 1) might be more likely but it’s just a guess honestly.

i have changed the code now for better accesibility.

  1. As you can see, if there is an Input like W,A,S,D then there is a direction which ends in movement.
    There also is no return in the whole function.
  2. The velocity or direction or speed aren’t getting changed somewhere outside this script.
  3. If I had the Inputs in the wrong order I would see if would be going up instead of going right.

Anyways thanks for pointing it out and maybe with this context you can help me.

$Sprites = AnimatedSprites2D
$footstep = AudioStreamPlayer2D

_anim(direction):
if dir.x == 1:
$Sprites.play(“walking right”)
if dir.x == -1:
$Sprites.play(“walking left”)
if dir.y == 1:
$Sprites.play(“walking down”)
if dir.y == -1:
$Sprites.play(“walking up”)
if dir.x> 0.5 and dir.y< -0.5:
$Sprites.play(“walking upright”)
if dir.x> 0.5 and dir.y> 0.5:
$Sprites.play(“walking downright”)
if dir.x< -0.5 and dir.y< -0.5:
$Sprites.play(“walking upleft”)
if dir.x< -0.5 and dir.y> 0.5:
$Sprites.play(“walking downleft”)
I at first thought it may be performance issues but after stripping the whole main scene down to just the player it still was like before.

I found the problem.
It is my keyboard. It has to be since today that it didn’t work properly i guess.