I need a little help with the animation pls

hey, this code is from the player and i have a problem whit the animation of atack, ikn why but when i do the action of hit it stays in a loop doing this
image
the other animation it´s ok, i put the code here:extends CharacterBody2D

@export var speed = 100
var life = 20
@onready var AniSprite = $AnimatedSprite2D
var last_direction = “down” # Variable para almacenar la última dirección
var atacando = false #Variable para indicar si el personaje está atacando

Movimiento del personaje

func get_input():
if not atacando: # Solo permitir el movimiento si no está atacando
var input_direction = Input.get_vector(“left”, “right”, “up”, “down”)
velocity = input_direction * speed

Función que se ejecuta en cada frame de física

func _physics_process(delta):
get_input_acciones()
if atacando:
velocity = Vector2.ZERO
else:
get_input()

if not atacando:# Solo cambiar la animación si no está atacando
	if velocity.x > 0:
		AniSprite.flip_h = false
		AniSprite.play("I_D_C")
		last_direction = "right"
	elif velocity.x < 0:
		AniSprite.flip_h = true
		AniSprite.play("I_D_C")
		last_direction = "left"
	elif velocity.y < 0:
		AniSprite.play("up_C")
		last_direction = "up"
	elif velocity.y > 0:
		AniSprite.play("down_C")
		last_direction = "down"
	else:
		if last_direction == "right":
			AniSprite.flip_h = false
			AniSprite.play("I_D")  # Animación de reposo mirando a la derecha
		elif last_direction == "left":
			AniSprite.flip_h = true
			AniSprite.play("I_D")  # Animación de reposo mirando a la izquierda
		elif last_direction == "up":
			AniSprite.play("up_Q")  # Animación de reposo mirando hacia arriba
		else:
			AniSprite.play("down_Q")  # Animación de reposo mirando hacia abajo
	
	move_and_slide()

func get_input_acciones():

if Input.is_action_just_pressed("atacar"):
	atacando = true
	match last_direction:
		"down":
			AniSprite.play("atacar_DOWN")
		"up":
			AniSprite.play("atacar_UP")
		"right":
			AniSprite.flip_h = false
			AniSprite.play("atacar_ID")
		"left":
			AniSprite.flip_h = true
			AniSprite.play("atacar_ID")
	print("ATACAR ACCION")
	#ahora acá debe ejecutarse la animacion de atacar
elif Input.is_action_just_pressed("objeto"):
	print("USA OBJETO")
	#por ahora sin cambios
elif Input.is_action_just_pressed("menu"):
	print("USAR MENU")
	#por ahora sin cambios

func _on_animated_sprite_2d_animation_finished():
if AniSprite.animation.begins_with(“atacar”):
atacando = true

Is your animated sprite 2d’s attack animation set to loop? When pasting code make sure it’s between three ticks, the </> or ctrl+e in the forum will create this for you

```
type or paste code here
```

1 Like

HAHAHAHHA LOVE U
image

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.