I have a 2d topdown rpg state machine but it gets stuck the moment i start walking. here is the code
extends CharacterBody2D
@onready var AnimSprite = $AnimatedSprite2D
@onready var ColShape = $CollisionShape2D
# Variables #
const SPEED = 300.0
var InputDirection = Vector2(0,0)
# State Machine #
enum State {IDLE, WALKING}
var state = State.IDLE
var AnimState = "Idle"
func CheckState():
if InputDirection != Vector2.ZERO: state = State.WALKING
func _input(_event):
InputDirection.x = Input.get_axis("Move Left", "Move Right")
InputDirection.y = Input.get_axis("Move Up", "Move Down")
func _physics_process(_delta):
match state:
State.IDLE:
CheckState()
AnimState = "Idle"
State.WALKING:
CheckState()
AnimState = "Walk"
velocity = InputDirection.normalized() * SPEED
move_and_slide()
print(AnimState)