How can i change an animation from attack back to idle?

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

Hy, i don’t know how to change the animation back to idle when the attack anim has finished. Here is the code:

func _physics_process(delta):

if Input.is_action_pressed("ui_right"):
	if is_on_floor():
elif Input.is_action_pressed("ui_left"):
	if is_on_floor():
elif is_on_floor():
if is_on_floor() and Input.is_action_just_pressed("ui_up"):
if is_on_floor() and Input.is_action_just_pressed("attack"):

if !is_on_floor():


Did you solve the problem?

BrunoFreezee | 2018-06-15 18:15

:bust_in_silhouette: Reply From: bitwes

AnimationPlayer has a ‘finished’ signal you can connect to. It passes the animation that finished. You can check that and kick off a different animation.

:bust_in_silhouette: Reply From: Socrates

Create a variable that refers to the string name of the current animation. Connect the AnimatedSprite’s animation_finished signal to a function:

$AnimatedSprite.connect("animation_finished", self, "name_of_function")

The function can check if the variable == “attack1” and then change it to “idle” if so. This requires replacing the string literals referring to the animations with the variable, which will be changed whenever you want to change animations.

:bust_in_silhouette: Reply From: KND2501

Below the walk inputs you can place…

	motion.x = 0
	if is_on_floor():