Player doesnt have movement but it does have animations of idle and walk

Godot Version

v4.5.stable.steam [876b29033]

Question

there are no errors. im pretty sure the error is somewhere in godots editor. my player has animations, idle and walk, but there is no movement. here is my walk_state script

extends NodeState

@export var player: CharacterBody2D
@export var animated_sprite_2d: AnimatedSprite2D
@export var speed: int = 50

func _on_process(_delta : float) → void:
pass

func _on_physics_process(_delta : float) → void:
var direction: Vector2 = GameInputEvents.movement_input()

if direction == Vector2.DOWN:
	animated_sprite_2d.play("walk_back")
elif direction == Vector2.UP:
	animated_sprite_2d.play("walk_front")
elif direction == Vector2.LEFT:
	animated_sprite_2d.play("walk_left")
elif direction == Vector2.RIGHT:
	animated_sprite_2d.play("walk_right")


player.velocity = direction * speed
player.move_and_slide()

func _on_next_transitions() → void:
pass

func _on_enter() → void:
pass

func _on_exit() → void:
pass

here is my game_input_script
class_name GameInputEvents

static var direction: Vector2

static func movement_input() → Vector2:

if Input.is_action_pressed("walk_left"):
	direction = Vector2.LEFT
elif Input.is_action_pressed("walk_right"):
	direction = Vector2.RIGHT
elif Input.is_action_pressed("walk_up"):
	direction = Vector2.UP
elif Input.is_action_pressed("walk_down"):
	direction = Vector2.DOWN
else:
	direction = Vector2.ZERO
	
return direction

static func is_movement_input() → bool:
if direction == Vector2.ZERO:
return false
else:
return true

i am using a state machine and i am going off of RapidVectors tutorial (pt 3) on youtube. thank you so much!

To post multi-line GDScript code, please put the entire thing between two sets of three backticks, like this:
```gd
# code
```

Have you tried printing the velocity? (print(player.velocity) at the very end of `_on_physics_process``) Is there any chance the player is colliding with that tree to its top right?

thank you, i ended up looking at the debug menu and seeing that it was colliding with everything! i accidentally put characterbody2d inside of animationbody2d, instead of having characterbody2d on top.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.