How to play an animation with a keyboad input

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

I want to play an a 4 frames animation, and i have tried with this code:

func _input(event):
var grounded = is_on_floor()
if grounded and Input.is_action_just_pressed(“attack1”):
$AnimationPlayer.play(“attack”)

and i already tried in this way:

func _input(event):
if Input.is_action_just_pressed(“attack1”):
$AnimationPlayer.play(“attack”)

but my character just stop the animation and dont play the current animation to attack.

What i can try? Its just the animation thats too small??

Have you checked if the attack animation works as you want before running the code? Maybe the animation itself is not running properly and is just stuck at Frame 1 (hence why it appears to “stop”).

Yuminous | 2021-07-10 08:39

The animation its working properly, but when i run this code, doesnt run even the first frame of the animation, i really dont understand whats happening

Heres my screen

if grounded:
	if move_dir == 0:
		play_anim("idle")
	else:
		play_anim("walk")
else:
	play_anim("jump")
#Bater no teto
if is_on_ceiling():
	y_velo = 0

I have that above in my code, this can be the cause?

AlanCcE | 2021-07-10 08:48

:bust_in_silhouette: Reply From: alshahriorhasan

Make sure to create an Input Map Action for attack1. Go to Project → Project Settings → Input Map. Type Action name then click add then add key for that action.

:bust_in_silhouette: Reply From: Snail0259

Make sure that in project settings -> input map there is an action called attack1, and it does have an action attached to it