my attack animation freezes and cant figure out why.

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

i have a problem where it seems when landing during the attack animation it freeze. i tried many time to make it happens and sometimes i succeed. but it dosent always happen. i usually spam buttons and jumping on a platform it seems to happen. it freeze pointing either directions aswell, so im guessing it has something with on_floor code that seems to do something. if you could spot something that might indicate the problem i would be greatfull.

enter codfunc _process(delta):
if Input.is_action_pressed("ui_right"):
		velocity.x = min(velocity.x+acceleration, max_run_speed)
		if is_attacking == false:
			$AnimatedSprite.play("run")
			$AnimatedSprite.flip_h = false
			if sign($Position2D.position.x) == -1:
				$Position2D.position.x *= -1
elif Input.is_action_pressed("ui_left"):
		velocity.x = max(velocity.x-acceleration, -max_run_speed)
		if is_attacking == false:
			$AnimatedSprite.play("run")
			$AnimatedSprite.flip_h = true
			if sign($Position2D.position.x) == 1:
				$Position2D.position.x *= -1
else:
	velocity.x = 0 
	if on_ground == true && is_attacking == false:
		$AnimatedSprite.play("idle")e here

if Input.is_action_just_pressed("ui_up"):
	#if on_ground == true:
		#velocity.y = jump_speed
		#on_ground = false
		if jump_count < 2:
			jump_count += 1
			velocity.y = jump_speed
			on_ground = false
if Input.is_action_just_pressed("ui_focus_next") && is_attacking == false:
	is_attacking = true
	$AnimatedSprite.play("attack")
	var fireball = FIREBALL.instance()
	if sign($Position2D.position.x) == 1:
		fireball.set_fireball_direction(2)
	else:
		fireball.set_fireball_direction(-2)
	get_parent().add_child(fireball)
	fireball.position = $Position2D.global_position
            velocity.y += gravity * delta



velocity = move_and_slide(velocity, Floor)
if is_on_floor():
	on_ground = true
	jump_count = 0
else:
	if is_attacking == false:
		on_ground = false
		if velocity.y >0:
			$AnimatedSprite.play("fall")
		elif velocity.y <0:
			$AnimatedSprite.play("jump")
	

func _on_AnimatedSprite_animation_finished():
is_attacking = false

I see you are calling play every frame here. Are you sure you are not trying to play multiple animations at once during the same frame? Someone had a similar issue before and the problem was caused by playing two animations per frame: the player started the first one, but had to stop it to start the second, and this every frame, the result being a frozen character.

Zylann | 2019-09-02 18:46

hello. i think you were right. i turned some of the animations with only 1 pic to 0 frames. and my jump animation that did not execute good, i made not loop. and now it seems to work fine :slight_smile:

deezy | 2019-09-03 16:35