How to switch Animations when key is released (in Statemachine)

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

I am using GameEndeavors statemachine.

In my block state I have two animations, one for when I am moving and when I am standing still. I got the standing still animation working correctly and trasitioning into the moving block animation but the problem is when playing the moving block animation, the player continues to show the moving block animation even after I come to a stand still, I want it to switch back to the idle block animation

Heres a look at some of the code.

The transition code.

states.block:
		if Input.is_action_pressed("block") && parent.move_input_speed != 0:
			return states.block
		elif !Input.is_action_pressed("block") && parent.is_on_floor():
			parent.anim_player.play("BlockEnd")
			#if parent.is_on_floor():
			if parent.velocity.x == 0:
				return states.idle
			else:
				return states.run
		elif !parent.is_on_floor():
			if parent.velocity.y < 0:
				return states.jump
			else:
				return states.fall
		

In the enter state I call a function called block()
func block():

if is_on_floor():

	if move_input_speed == 0:
		anim_player.play("Block")
	else:		
		anim_player.play("BlockRun")
		#Reduce move speed by half when blocking
		move_speed = (speed/2) * Globals.UNIT_SIZE 

What I want to happen is when I let go of the left or right key(move_input_speed == 0)
, I want it to stop playing the block run anim and switch to regular block anim

Sorry if this was confusing and hard to follow, thanks for your help.

:bust_in_silhouette: Reply From: LotusOrb

solved the issue by checking if animplayer is playing block run and move input speed = 0, then play block anim

:bust_in_silhouette: Reply From: LotusOrb

states.block:
if !parent.is_on_floor():
if parent.velocity.y < 0:
return states.jump
else:
return states.fall
elif parent.anim_player.current_animation == “BlockRun” && parent.move_input_speed == 0:
return states.block
elif Input.is_action_pressed(“block”) && parent.move_input_speed != 0:
return states.block
elif !Input.is_action_pressed(“block”) && parent.is_on_floor():
parent.anim_player.play(“BlockEnd”)
#if parent.is_on_floor():
if parent.velocity.x == 0:
return states.idle
else:
return states.run

if is_on_floor():

	#anim_player.current_animation == "BlockMove"
	if anim_player.current_animation == "BlockRun" && move_input_speed == 0 :
		anim_player.play("Block")
		anim_player.seek(.1, true)
		#anim_player.seek(.77, true)
		#anim_player.stop()
	elif move_input_speed == 0:
		anim_player.play("Block")
		
	#elif anim_player.current_animation == "BlockRun":# && move_input_speed == 0 :
	#	anim_player.play("Block")
	else:		
		anim_player.play("BlockRun")
		#Reduce move speed by half when blocking
		move_speed = (speed/2) * Globals.UNIT_SIZE 

The changes I made to get desired results