0 votes

Hello! it is me again.
I have another question and it is related to the animations of my platform character and it is that no animation works as it should or I don't know if I have indicated it incorrectly,
when the character jumps the jump animation doesn't work correctly, and the wall slide animation doesn't advance it's three frames but being on the wall only the first frame is shown and also the falling animation doesn't show as it should you can copy the code and make the animations so you can see why it doesn't work, when the character jumps the jump animation doesn't work correctly, and the wall slide animation doesn't advance it's three frames but being on the wall only the first frame is shown and also the falling animation doesn't show as it should you can copy the code and make the animations so you can see why it doesn't work, I would greatly appreciate it

Here is the code of the character

extends KinematicBody2D

export (int) var speed = 175
export (int) var jump_speed = -400
export (int) var gravity = 800

const wall_slide_speed = 82.5
const wall_slide_gravity = 400

var is_wall_sliding : bool = false

var velocity = Vector2.ZERO

func get_input():
    velocity.x = 0
    if Input.is_action_pressed("ui_right"):
        velocity.x += speed
        $AnimatedSprite.flip_h = false
        $AnimatedSprite.play("RUN")
    elif Input.is_action_pressed("ui_left"):
        velocity.x -= speed
        $AnimatedSprite.flip_h = true
        $AnimatedSprite.play("RUN")
    elif velocity.y < 0:
        $AnimatedSprite.play("JUMP")
    elif velocity.y > 0:
        $AnimatedSprite.play("FALL") 
    elif is_on_wall() and velocity.y > 0:
        $AnimatedSprite.play("WALL_SLIDE")

    else:
        $AnimatedSprite.play("IDLE")






func _physics_process(delta):
    get_input()
    velocity.y += gravity * delta
    velocity = move_and_slide(velocity, Vector2.UP)
    if Input.is_action_just_pressed("ui_up"):
        if is_on_floor():
            velocity.y -= 400
            $AnimatedSprite.play("JUMP")
    if is_on_wall() and not is_on_floor():
        if Input.is_action_pressed("ui_right") or Input.is_action_pressed("ui_left"):
            is_wall_sliding = true
        else:
            is_wall_sliding = false

    else:
        is_wall_sliding = false


if is_wall_sliding == true:
    velocity.y += wall_slide_gravity * delta
    velocity.y = min(velocity.y, wall_slide_speed)
    $AnimatedSprite.play("WALL_SLIDE")
Godot version Godot_v3.4.3
in Engine by (36 points)
edited by

If you write more legibly we can help.

like this

func examples():
      blabla

If you highlight your code and click the {} button it will make the code legible for us. Also it would be helpful if you could explain how your animation isnt working, do you mean you get the wrong animation or it starts to play and then stops or restarts again?

I updated the question

func _physics_process(delta):
      // current.animation 
     //we must find current animation 
     print($AnimatedSprite.name) // name of the animation playing
     //forgot the code
    // query the name of the animation that is playing at that moment.
   // You will find the source of the problem

1 Answer

0 votes
Best answer

I think you have made the same mistake as a previous question I answered

https://godotengine.org/qa/128154/animation-stuck-on-first-frame

if you separate out your animation into a separate function from the inputs you can base it on the movement rather than the inputs.

by (1,589 points)
selected by
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.