0 votes

hello, so I recently got into game development as a hobby and started learning GDscript as my first programing language so I apologize if my code looks bad, I also apologize if I make any grammatical errors or I am not as clear as I could be English is not my first language. for clarity sake let me explaining what nodes I am using. my node tree consists of a Node2D a KinematicBody2D, AnimatedSpritt2D, CollisionShape2D. I am not using an AnimationPlayer Node because it would not work well with traditional sprite animation seems sprite sheet settings are not particularly outstanding. and seems I am developing a traditional 2d fighter having good traditional 2d animation is important for me.

so when I was programming the player characters' movements and animation, I hit a stumbling block when I was programming the player crouching or ducking animation. you see my goal is to have the animation play such as that when the player presses the down input the character sprite will stop playing the standing idle animation and play a quick crouching down animation, then if the player continues holding down the character will play there crouching idle animation so long as the input for down is press.but when the player lets go of the down input or release it, the character will plays a quick standing up animation and return back to neutral or there standing idle animation.

so my first attempt to do this used the Input.is_action_just_pressed("down")to trigger the crouching down animationInput.is_action_pressed("down") so when the player hold down on the crouching bottom it will play a crouching idle, and lastly Input.is_action_just_released("down") so that when the player is no longer pushing down it will play the standing up animation and return to standing idle.

but this, unfortunately, did not work because apparently is_action_just_pressed() and is_action_just_released() only return true for one frame, meaning it's true only on the frame that the user pressed down, so only the first frame of animation will play for just a short moment. so these will unfortunately not work as I intended it to. I need the whole animation to play first before moving to the next animation.

my second attempt was using the_input(event)function to hopefully get the desired result with theaction_release action_press methods. this, unfortunately, didn't work like I thought it would. I'm sorry if this isn't as detailed as my first attempt but I my-self don't really understand how this function worked but it didn't seem like it was gonna work I thought it would.

my third and last attempt so far was using signals to try and tell the game when one animation was finish to start another different animation. however, this made this error message pop up Stack Overflow I'm not exactly sure what this means or how to even begin to fix it seems I'm I just recently started learning to code so I'm not too familiar with coding terminology.

here is my code so far apologize if it looks amateurish or messy

extends KinematicBody2D

"PLAYER BASIC CONTROLS"

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

var motion = Vector2()
var jumpheight = Vector2(0,-900)
var jump
forward = Vector2(400,-900)
var jump_backward = Vector2(-400,-900)

func ready():
pass
func is
actionreleased(event):
pass
func normal
attacks(delta):
pass
func Specialattacks(delta):
pass
set
process_input(true)
func _input(event):

if(event.is_action_pressed("down")):
    print("low")
if is_on_floor():
    if(event.is_action_released("down")):
        print("LOW")
        $Ryu_sprite.play("crouching stand")

func physicsprocess(delta):

motion.y += GRAVITY
motion = move_and_slide(motion,UP)
player_movement()

func playermovement():
if is
on_floor():
motion.y = 0
motion.x = 0

this line of code below is to prevent keyboard and hitbox players from moving and charging move at the same time

    if Input.is_action_pressed("right") and Input.is_action_pressed("left") and Input.is_action_pressed("down"):
        motion.x = 0
        motion.y = 0
        $Ryu_sprite.play("idle")

    elif Input.is_action_pressed("up") and Input.is_action_pressed("down"):
        motion.x = 0
        motion.y = 0
        $Ryu_sprite.play("crouching idle")

this line of code above is to prevent keyboard and hitbox players from moving and charging moves at the same time

    elif Input.is_action_just_pressed("down"):
        motion.x = 0
        $Ryu_sprite.play("crouching")
        print("crouching animation was played")

    elif Input.is_action_pressed("down"):
        motion.x = 0
        $Ryu_sprite.play("crouching idle")


    elif Input.is_action_just_released("down"):
        $Ryu_sprite.play("crouching stand")
        print("crouching stand animation was played")
    elif Input.is_action_pressed("right"):

        motion.x = SPEED
        $Ryu_sprite.play("walk b")
        $Ryu_sprite.flip_h = false

    elif Input.is_action_pressed("left"):

        motion.x = -SPEED
        $Ryu_sprite.play("walk f")
        $Ryu_sprite.flip_h = false

    else:
        motion.x = 0
        $Ryu_sprite.play("idle")

    if Input.is_action_pressed("up"):
        $Ryu_sprite.play("jump")
        motion = jump_height

        if Input.is_action_pressed("right"):
            $Ryu_sprite.play("jump b")
            motion = jump_forward
        elif Input.is_action_pressed("left"):
            $Ryu_sprite.play("jump f")
            motion = jump_backward

motion = move_and_slide(motion,UP)

Any help is greatly appreciated

asked Mar 20 in Engine by Aby_is_a_kitkat (18 points)

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.