How do I get player character animation to correctly animate using func _input(event)

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

So I was writing code for my player character movement and I’m a little lost as to how to fix I problem, I ran into. you see the way I want the animation to work is to seamlessly transition between actions such as walking, jumping, crouching. so after a long time of trial and error, I found out I could use _input(event) and the yield keyword for some of the transitional animations that were giving me trouble. for the most part this workout well but time giving problems getting the standing up animation to work. you see when it’s only func _input(event): the crouching, crouching idle, and crouching stand up animation work correctly but when I activate func _player_movement(): the standing up animation will stop working correctly. I’m sorry if this is a very easy problem and I’m just dumb. bare with me I’m fairly new to coding. thank you any help his greatly appreciated`

extends KinematicBody2D

"PLAYER CHARACTER CONTROLS"

 const UP = Vector2(0,-1)
 const GRAVITY = 35
 const VELOCITY = 20

 var motion = Vector2(0,0)
 var walk_speed =Vector2(400,0)
 var jump_height = Vector2(0,-900)
 var jump_forward = Vector2(-400,-900)
 var jump_backward = Vector2(400,-900)

func _physics_process(delta):
motion.y += GRAVITY
motion = move_and_slide(motion,UP)
if is_on_floor():
	   motion.y = 0
	   motion.x = 0
	   player_character_movement()
func _input(event):
   if is_on_floor():
	   motion.y = 0
	   motion.x = 0
	   get_node("AnimatedSprite").play("default")
	   if (event.is_action_pressed("ui_down")):
		   get_node("AnimatedSprite").play("crouching")
	         yield(get_node("AnimatedSprite"),"animation_finished")
	if Input.is_action_pressed("ui_down"):
		get_node("AnimatedSprite").play("crouching idle")
	if (event.is_action_released("ui_down")):
		get_node("AnimatedSprite").play("crouching stand")
		yield(get_node("AnimatedSprite"),"animation_finished")
		get_node("AnimatedSprite").play("default")
  func animation_finished():
      print("an animation has been completed")
  func player_character_movement():
      if  is_on_floor():
	      motion.y = 0
	      motion.x = 0
	     if Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_right"):
		     motion.x = 0
	    elif Input.is_action_pressed("ui_down") and Input.is_action_pressed("ui_left"):
		    motion.x = 0
	    if Input.is_action_pressed("ui_down"):
		    motion.x = 0
	    elif Input.is_action_pressed("ui_left"):
		    motion = -walk_speed
		    get_node("AnimatedSprite").play("walk F")
	    elif Input.is_action_pressed("ui_right"):
		  motion = walk_speed
		  get_node("AnimatedSprite").play("walk B")
	    else:
		  get_node("AnimatedSprite").play("default")
	if Input.is_action_pressed("ui_up"):
		get_node("AnimatedSprite").play("jump")
		motion = jump_height
		if Input.is_action_pressed("ui_left"):
			get_node("AnimatedSprite").play("jump F")
			motion = jump_forward
		elif Input.is_action_pressed("ui_right"):
			get_node("AnimatedSprite").play("jump B")
			motion = jump_backward`

Please format your code properly: each line of code has to be indented by four spaces to be recognized as part of the code block. Any additional set of four spaces will indent your code by another layer. Use the preview to ensure that it works: codeblocks will be shown as a box with a gray background. You can edit your question by clicking on the three dots in the bottom right corner and selecting “Edit”. Not doing so means every underscore in your code is interpreted as Markdown formatting (for italic text). Also all indentation levels are lost, which makes your code very hard to read.

njamster | 2020-06-16 12:46