0 votes

When i click the button my kick-jump and punch just activate 1st frame of animated sprite. These are the pictures:
This one is is_action_just_pressed and just show the first frame of the action
enter image description hers
This one is is_action_pressed and i have to stay pushed
enter image description here

extends KinematicBody2D

export var jump_count = 0
const MAX_JUMP_COUNT = 2
#!Sprint
const SPRINT_ACCELARATION = 175
const SPRINT_SPEED = 700

const MAX_SPEED = 350
const GRAVITY = 20
const JUMP = -600
const WALL_SLIDE = 100

const ACCELARATION = 50
var crouch_air = 50

var motion = Vector2()
const RESISTANCEGRAV = Vector2(0, -1)

func _physics_process(delta):
    #!Falling Death

    if motion.y > 1750: # change as needed
    get_tree().reload_current_scene()

    motion.y += GRAVITY

    var friction = false

    if Input.is_action_pressed("ui_right"):
        motion.x += ACCELARATION
        motion.x = min(motion.x, MAX_SPEED)
        $plyr_sprite.flip_h = false
        $plyr_sprite.play("Run")
        if Input.is_action_pressed("ui_sprint"):
            motion.x += SPRINT_ACCELARATION
            motion.x = min(motion.x, SPRINT_SPEED)

    elif Input.is_action_pressed("ui_left"):
        motion.x -= ACCELARATION
        motion.x = max(motion.x, -MAX_SPEED)
        $plyr_sprite.flip_h = true
        $plyr_sprite.play("Run")
        if Input.is_action_pressed("ui_sprint"):
            motion.x -= SPRINT_ACCELARATION
            motion.x = max(motion.x, -SPRINT_SPEED)

    # Punch and Kick on floor
    elif Input.is_action_just_pressed("ui_punch"):
        $plyr_sprite.play("Punch")
        motion.x = 0

    elif Input.is_action_just_pressed("ui_kick"):
        $plyr_sprite.play("Kick")
        motion.x = 0

    else:
        friction = true
        $plyr_sprite.play("Idle")
        if friction == true:
            motion.x = lerp(motion.x, 0, 0.2)

    if is_on_floor():
        jump_count = 0
        $plyr_hitbox.disabled = false
        $plyr_hitbox_crouch.disabled = true
        if Input.is_action_pressed("ui_down") && Input.is_action_pressed("ui_right"):
            $plyr_sprite.play("Run")
        elif Input.is_action_pressed("ui_down") && Input.is_action_pressed("ui_left"):
            $plyr_sprite.play("Run")
        elif Input.is_action_pressed("ui_down"):
            $plyr_sprite.play("Crouch")
            $plyr_hitbox.disabled = true
            $plyr_hitbox_crouch.disabled = false

        if Input.is_action_just_pressed("ui_up"):
            if jump_count < 2:
                motion.y = JUMP
                jump_count += 1

        if friction == true:
            motion.x = lerp(motion.x, 0, 0.1)

    else:

        if jump_count < 2 && Input.is_action_just_pressed("ui_up"):
            motion.y = JUMP
            $plyr_sprite.play("Jump")
            jump_count += 1
        elif motion.y < 0 && !Input.is_action_pressed("ui_down"):
            $plyr_sprite.play("Jump")
        elif motion.y > 0 && !Input.is_action_pressed("ui_down"):
            $plyr_sprite.play("Fall")
        elif motion.y > 0 && Input.is_action_pressed("ui_down"):
            $plyr_sprite.play("Crouch")
        if friction == true:
            motion.x = lerp(motion.x, 0, 0.05)

    if is_on_wall():
        jump_count = 1
        #Wall Sliding Sprite with 1 picture
        #$plyr_sprite.play("Punch")
        if motion.y > 0:
            motion.y = WALL_SLIDE
        if Input.is_action_pressed("ui_right") and Input.is_action_just_pressed("ui_left"):
            motion.y = JUMP * .8
        if Input.is_action_pressed("ui_left") and Input.is_action_just_pressed("ui_right"):
            motion.y = JUMP * .8

    motion = move_and_slide(motion, RESISTANCEGRAV)

When i click the button my kick-jump and punch just activate 1st frame of animated sprite.
This one is is_action_pressed and i have to stay pushed
This one is is_action_just_pressed and just show the first frame of the action

in Engine by (15 points)
edited by

1 Answer

+1 vote
Best answer

The problem is here

 else:
     friction = true
     $plyr_sprite.play("Idle")

You need to allow time for the animation to play before playing idle. You can do this by adding delta to a float and checking if the float is above a number of seconds. You can do something like this

 else:
     friction = true
     #a new bool to check if the player's idle
     is_idle = true

and

func _process(delta):
    if time_float < time_allowed:
        time_float += delta
    elif is_idle:
        #start idle
        $plyr_sprite.play("Idle")

        #don't repeat the line above
        is_idle = false

You'll have to reset time_float back to 0 every time the player moves.

by (3,227 points)
selected by

thanks i fixed it with your help :)

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.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.