Search code examples
2dgame-developmentgodot

Godot end movement with animation


I am using the given godot 2D platformer movement and made my own custom inputs. One of which is a slide. When the slide input is made, it plays a sliding animation and increases the speed. At the end of the animation, the character stands up. How do I make the character stop the animation and set the speed back to normal when it's finished.

and not(Input.is_action_pressed("slide")):
    velocity.y = JUMP_VELOCITY

var direction = Input.get_axis("left", "right")

if direction > 0:
    animated_sprite.flip_h = false
elif direction < 0:
    animated_sprite.flip_h = true

if direction == 0:
    animated_sprite.play('default')
else:
    if Input.is_action_pressed("slide"):
        animated_sprite.play("slide")
        animation_player.play("slide")
        SPEED = 150.0
    else:
        animated_sprite.play("run")
        animation_player.play("RESET")
        SPEED = 120.0

if direction:
    velocity.x = direction * SPEED
else:
    velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

Feel free to ask questions for more info.


Solution

  • You can call functions directly from animation keyframes using a “Call Method” animation track. The new video tutorial by Brackeys shows this here: https://youtube.com/watch?v=LOhfqjmasi0&t=4398

    You could also use the await keyword to wait for the animation_finished signal:

    if Input.is_action_just_pressed("slide"):
        animation_player.play("slide")
        SPEED = 150.0
        await animation_player.animation_finished
        SPEED = 120.0