extends CharacterBody2D
@onready var player_anim = $AnimatedSprite2D
var player_speed := 75
var player_direction := 0.00 #-1 or 1 direction
var is_attacking = false
var is_walking = false
func _physics_process(delta):
player_direction = 0 #resets direction to 0 when we let go of input
#problems:
#need a loop that returns animation to idle instead
if Input.is_action_pressed("move_left"):
player_direction = -1
player_speed * player_direction
is_walking = true
is_attacking = false
print(player_direction)
if player_direction < 1:
player_anim.flip_h = true
player_anim.play("walk")
elif Input.is_action_pressed("move_right"):
player_direction = 1
player_speed * player_direction
is_walking = true
is_attacking = false
print(player_direction)
if player_direction == 1:
player_anim.flip_h = false
player_anim.play("walk")
elif Input.is_action_just_pressed("attack"):
player_direction = 0
player_speed * player_direction
is_walking = false
is_attacking = true
if is_walking == false and is_attacking == true:
player_anim.play("attack")
else:
player_anim.play("idle")
velocity.x = player_speed * player_direction
move_and_slide()
4.2.2
Question
I need help with my player animation. I’m trying to get the attack animation to play when pressing the attack input while also stopping the movement of the player. I tried different things to get it to work, but when I press the attack input, the animation slightly stutters and goes back to either walking or idle. I also tried attacking while moving but it still does the same thing. How can I get this to loop correctly? Any tips on fixing this would be greatly appreciated!