+1 vote

trying to make a simple platformer but the slide and jump animations only play the first frame, i tried every thing (associating the animations with variables and other things and i keep running into the same problem, godot only plays the first frame, however i dont have that problem with the run animation. here is my code)

extends KinematicBody2D

const UP = Vector2(0,-1)
const GRAVITY = 20
const SPEED = 300
const JUMP_HEIGHT = -700

var velocity = Vector2()
var climbing = false;
var is_jumping = false

func _process(delta):
velocity.y += GRAVITY

if Input.is_action_pressed("right"):
    velocity.x = SPEED
    $AnimatedSprite.play("run")
    $AnimatedSprite.flip_h = false

elif Input.is_action_pressed("left"):
    velocity.x = -SPEED
    $AnimatedSprite.play("run")
    $AnimatedSprite.flip_h = true

if Input.is_action_pressed("left"):
    if Input.is_action_pressed("down"):
        velocity.x = -SPEED * 2
        $AnimatedSprite.play("slide")
        $standingshape.disabled = true
        $crouchshape.disabled = false

elif Input.is_action_pressed("right"):
    if Input.is_action_pressed("down"):
        velocity.x = SPEED * 2 
        $AnimatedSprite.play("slide")
        $standingshape.disabled = true
        $crouchshape.disabled = false


#else:
    velocity.x = SPEED - SPEED
    $AnimatedSprite.play("idle")
    $standingshape.disabled = false


if is_jumping == true:
    $AnimatedSprite.play("air")

if not.is_on_floor():
    $AnimatedSprite.play("air")

if.is_on_floor():
    if Input.is_action_pressed("up"):
        $AnimatedSprite.play("air")
        velocity.y = JUMP_HEIGHT


if.is_on_wall():
    if Input.is_action_pressed("up"):
        climbing = true;
        $AnimatedSprite.play("climb")
        velocity.y = -75

velocity = move_and_slide(velocity, UP)
in Engine by (13 points)

1 Answer

0 votes

My best guess is that it's only playing the first frame because it is constantly switching between the run and slide or jump animations

If the player is pressing right and down, your code will first check if it's moving right and play the run animations, then checking if it's sliding and so play the slide animation.

Because godot thinks you are already playing the run animation, it will start the slide animation from the start.

I would recommend combining both times you have an if statement about the horizontal axis. Possibly:

if Input.is_action_pressed("left"):
    velocity.x = -SPEED
    $AnimatedSprite.flip_h = true
    if Input.is_action_pressed("down"):
        velocity.x = -SPEED * 2
        $AnimatedSprite.play("slide")
        $standingshape.disabled = true
        $crouchshape.disabled = false
  else:        
        $AnimatedSprite.play("run")

elif Input.is_action_pressed("right"):
    velocity.x = SPEED
    $AnimatedSprite.flip_h = false
    if Input.is_action_pressed("down"):
        velocity.x = SPEED * 2 
        $AnimatedSprite.play("slide")
        $standingshape.disabled = true
        $crouchshape.disabled = false

  else:
        $AnimatedSprite.play("run")

Let me know if that doesn't work or you need more clarification

by (374 points)

hey bro i tried your code, the slide animation plays all the frames but when i spawn it is automatically playing the run animation and when i slide the animations plays all frames but no matter what i do i cant move

This might be my bad, but it's possible that the indentation is slightly weird? See if this makes a difference:
if Input.isactionpressed("left"):
velocity.x = -SPEED
$AnimatedSprite.fliph = true
if Input.is
action_pressed("down"):
velocity.x = -SPEED * 2
$AnimatedSprite.play("slide")
$standingshape.disabled = true
$crouchshape.disabled = false
else:
$AnimatedSprite.play("run")

elif Input.is_action_pressed("right"):
    velocity.x = SPEED
    $AnimatedSprite.flip_h = false
    if Input.is_action_pressed("down"):
        velocity.x = SPEED * 2 
        $AnimatedSprite.play("slide")
        $standingshape.disabled = true
        $crouchshape.disabled = false

    else:
        $AnimatedSprite.play("run")
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.

Categories