I want to prevent the character from moving during the attack

Hello, my goal is to stay still until the swing animation stops and then move after the swing animation ends. But now, when you press the direction input key during an attack, it moves in a swing state.

extends CharacterBody2D

const SPEED : float = 30.0 
const RUN : float = 100.0 

@onready var animation_tree : AnimationTree = $AnimationTree

var direction : Vector2 = Vector2.ZERO 

func  _ready():
	animation_tree.active = true 
func _process(_delta):

func  _physics_process(_delta):
	direction = Input.get_vector("left","right","up","down").normalized()
	if direction:
		if Input.is_action_pressed("Alt"):
			velocity = direction * SPEED
			velocity = direction * RUN
		velocity = Vector2.ZERO

func update_animation_parameters(): 
	if(velocity == Vector2.ZERO): 
		animation_tree["parameters/conditions/idle"] = true
		animation_tree["parameters/conditions/move"] = false
		animation_tree["parameters/conditions/idle"] = false 
		animation_tree["parameters/conditions/move"] = true
		if Input.is_action_pressed("Alt"): 
			animation_tree["parameters/move/conditions/is_moving"] = true
			animation_tree["parameters/move/conditions/is_run"] = false
			animation_tree["parameters/move/conditions/is_run"] = true 
			animation_tree["parameters/move/conditions/is_moving"] = false

		animation_tree["parameters/conditions/swing"] = true
		animation_tree["parameters/conditions/swing"] = false

	if(direction != Vector2.ZERO):
		animation_tree["parameters/idle/blend_position"] = direction
		animation_tree["parameters/move/walk/blend_position"] = direction
		animation_tree["parameters/move/run/blend_position"] = direction
		animation_tree["parameters/swing/swing_01/blend_position"] = direction

make a new variable called can_walk. and using the is_playing() function on the swing animation and set the variable to true or false. then just use:

if direction and can_walk:

maybe i’m wrong but i think this will work.