0 votes

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 _playermovement(): 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


 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
func _input(event):
   if is_on_floor():
       motion.y = 0
       motion.x = 0
       if (event.is_action_pressed("ui_down")):
    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")
  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")
    if Input.is_action_pressed("ui_up"):
        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`
asked Jun 16 in Engine by Aby_is_a_kitkat (18 points)
edited Jun 16 by Aby_is_a_kitkat

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.

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.