Attack animation stops movement

Godot Version

4.3

Question

So I have 8 way movement and attacking animations setup. You can move and attack at the same time in all directions but diagonally up and to the left. Up and to the right, down and to the right, and down and to the left all work without issue. But when I move up and to the left and try to attack, nothing happens. Move to the left and attack and then try to add the “up” input, I continue to go straight to the left. My code is below. I am pretty new to this so I might just be overlooking something/using some code the wrong way. Not sure but I am stumped either way! Any help or clues are appreciated!


@export var speed = 250
@onready var animated_sprite = $AnimatedSprite2D
@onready var coll_box = $CollisionShape2D
var direction = ""
var attacking = false

## Movement Funtion. Moves player and Collision box
func movement():
	var input_direction = Input.get_vector("left", "right", "up", "down")
	velocity = input_direction * speed
	if Input.is_action_pressed("up") and attacking == false:
		animated_sprite.play("Walk_Up")
		coll_box.position.x = 55.75
		coll_box.position.y = -15.5
		direction = "up"
	elif Input.is_action_pressed("left") and attacking == false:
		animated_sprite.play("Walk_Left")
		coll_box.position.x = 47
		coll_box.position.y = -20
		direction = "left"
	elif Input.is_action_pressed("right") and attacking == false:
		animated_sprite.play("Walk_Right")
		coll_box.position.x = 47
		coll_box.position.y = -20
		direction = "right"
	elif Input.is_action_pressed("down") and attacking == false:
		animated_sprite.play("Walk_Down")
		coll_box.position.x = 55.75
		coll_box.position.y = -15.5
		direction = "down"
	elif Input.is_action_just_released("down") or Input.is_action_just_released("up") or Input.is_action_just_released("left") or Input.is_action_just_released("right"):
		animated_sprite.play("Idle")
		coll_box.position.x = 55.75
		coll_box.position.y = -15.5
	attack()
	block()

## Plays attack animations based on the direction variable. Returns to idle animation after attacks
func attack():
	if Input.is_action_pressed("attack") and direction == "right":
		attacking = true
		animated_sprite.play("Swing_Right")
		coll_box.position.x = 50
		coll_box.scale.x = .2
		coll_box.scale.y = .22
	elif Input.is_action_just_released("attack"):
		animated_sprite.play("Idle")
		attacking = false
		coll_box.position.x = 55.75
		coll_box.position.y = -15.5
		coll_box.scale.x = .4
		coll_box.scale.y = .4
	if Input.is_action_pressed("attack") and direction == "left":
		attacking = true
		animated_sprite.play("Swing_Left")
		coll_box.position.x = 68
		coll_box.scale.x = .2
		coll_box.scale.y = .22
	elif Input.is_action_just_released("attack"):
		animated_sprite.play("Idle")
		attacking = false
		coll_box.position.x = 55.75
		coll_box.position.y = -15.5
		coll_box.scale.x = .4
		coll_box.scale.y = .4
	if Input.is_action_pressed("attack") and direction == "up":
		attacking = true
		animated_sprite.play("Swing_Up")
	elif Input.is_action_just_released("attack"):
		animated_sprite.play("Idle")
		attacking = false
	if Input.is_action_pressed("attack") and direction == "down":
		attacking = true
		animated_sprite.play("Swing_Down")
	elif Input.is_action_just_released("attack"):
		animated_sprite.play("Idle")
		attacking = false
		
## Plays block annimation based on direction variable. Returns to Idle animation after button is released. 
func block():
	if Input.is_action_just_pressed("block") and direction == "right":
		animated_sprite.play("Block_Right")
	elif Input.is_action_just_released("block"):
		animated_sprite.play("Idle")
	if Input.is_action_just_pressed("block") and direction == "left":
		animated_sprite.play("Block_Left")
	elif Input.is_action_just_released("block"):
		animated_sprite.play("Idle")
	if Input.is_action_just_pressed("block") and direction == "up":
		animated_sprite.play("Swing_Up")
	elif Input.is_action_just_released("block"):
		animated_sprite.play("Idle")
	if Input.is_action_just_pressed("block") and direction == "down":
		animated_sprite.play("Swing_Down")
	elif Input.is_action_just_released("block"):
		animated_sprite.play("Idle")

func _process(_delta):
	movement()
	move_and_slide()

1 Like

Please can you place the codes in proper format like this:

``` My Codes, I used this symbol for it ```
3 Likes

Done. Sorry about that!

2 Likes