0 votes

I can't make my jump animation active. I understand that it is because my main motion animation is still working.
I achieved my goal by modifying the code in this way

 func _ready():

 if is_on_floor():

        if jump:
            velocidad.y = jump_power

but there are times when the animation does not end correctly, which causes the button to skip the animation again to start the last time and so on.

I tried to do it in other ways but I don't get it to work or just start the first frame.

This is the whole code, I hope you give me a hand with this: D

extends KinematicBody2D

const movimiento = 500
const gravedad = 1500
const jump_power = -650
var velocidad = Vector2()

 func _physics_process(delta):

    var walk_left = Input.is_action_pressed("ui_left")
    var walk_right = Input.is_action_pressed("ui_right")
    var jump = Input.is_action_pressed("ui_up")
    var jump_stop = Input.is_action_just_released("ui_up")

    var on_wall = $CollisionShape2D/RayCast2D.is_colliding();

    if walk_left:

        if on_wall and $AnimatedSprite.flip_h and not is_on_floor():
            velocidad.y = jump_power

        velocidad.x = -movimiento
        $AnimatedSprite.flip_h = true
        $CollisionShape2D/RayCast2D.rotation_degrees = 270

    elif walk_right:

        if on_wall and not $AnimatedSprite.flip_h and not is_on_floor():
            velocidad.y = jump_power

        velocidad.x = movimiento
        $AnimatedSprite.flip_h = false
        $CollisionShape2D/RayCast2D.rotation_degrees = 90

        velocidad.x = 0

    if is_on_floor():
        if jump:
            velocidad.y = jump_power

    elif jump_stop and velocidad.y < 0:
        velocidad.y *= 0.5

    velocidad.y += gravedad * delta
    velocidad = move_and_slide(velocidad, Vector2(0, -1))
in Engine by (82 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 Frequently asked questions and 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 [email protected] with your username.