Attack animation only playing the first frame.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By RodFire8181

For two days I have been trying to get the attack animation for my player sprite to play completely, but it will only play the first frame. I have moved things around in my code quite a bit, but to avail. I’ve looked around at possible reasons for this to keep happening and tried to fix those things, but it still won’t play completely.
This is my current code.

`func _physics_process(delta):

motion.y += GRAVITY

if Input.is_action_pressed("ui_right"):
	if attacking == false:
		motion.x = SPEED
		$AnimatedSprite.flip_h = false
		$AnimatedSprite.play("Run")
elif Input.is_action_pressed("ui_left"):
	if attacking == false:
		motion.x = -SPEED
		$AnimatedSprite.flip_h = true
		$AnimatedSprite.play("Run")
else: 
	if attacking == false:
		motion.x = 0
		$AnimatedSprite.play("Idle")

if is_on_floor() && attacking == false:
	if Input.is_action_pressed("ui_up"):
		motion.y = JUMP_HEIGHT
	if Input.is_action_just_pressed("ui_down") && attacking == false:
		attacking == true
		$AnimatedSprite.play("Attack")
		if motion.x == 0:
			if $AnimatedSprite.flip_h == false:
				motion.x = 15
			elif $AnimatedSprite.flip_h == true:
				motion.x = -15
		else: 
			if $AnimatedSprite.flip_h == false:
				motion.x = SPEED + 15
			elif $AnimatedSprite.flip_h == true:
				motion.x = -SPEED + -15
else:
	if motion.y < 0:
		$AnimatedSprite.play("Jump")
	else: 
		$AnimatedSprite.play("Fall")


motion = move_and_slide(motion, UP)`

Am I doing something wrong? Is there something I need to change or add?

Backticks ` only work for one-liner. Use the { } button to format a block of code.

Dlean Jeans | 2019-06-09 03:40

Thank you. Good to know.

RodFire8181 | 2019-06-09 17:54

:bust_in_silhouette: Reply From: Dlean Jeans

Found a typo here:

attacking == true
$AnimatedSprite.play("Attack")

Should be:

attacking = true
$AnimatedSprite.play("Attack")

Coding Tips:

Instead of writing

if attacking == false:
# or
if $AnimatedSprite.flip_h == true:
# and 
if $AnimatedSprite.flip_h == false:

write

if not attacking:
# or
if $AnimatedSprite.flip_h:
# and
if not $AnimatedSprite.flip_h:

Thank you. This didn’t fix my proble but I appreciate it.

RodFire8181 | 2019-06-09 18:25

Try creating a function called is_attacking and use it in place of your attacking variable:

func is_attacking():
  return is_playing() and animation == "Attack"

Dlean Jeans | 2019-06-10 14:34