0 votes

Hi Everyone, I am making a 2d platformer in Godot engine. I have came across on issue.
In a lot of platformers when you try to run and you are on a wall the character plays idle animation. I wanted to implement this in my game. I tried to code that when I am on a wall
play the idle animation

if is_on_wall():
    $AnimatedSprite.play("idle")

But when I run this when the player is on a wall it plays the idle animation but it only the first frame
I also tried this:
if velocity.x == 0:
$AnimatedSprite.play("idle")
But is still plays the running animation because I am using a else statement for running animation

Can Someone help me with this?
Appreciated

Godot version 3.4.3 stable
in Engine by (73 points)
edited by

I'm going to go out on a limb here and guess that the code $AnimatedSprite.play("idle") is being run in the _physics_process() function. If that's true, then first check for whether the animation is playing. If not, then play it:

if is_on_wall() and $AnimatedSprite.animation != "idle":
    $AnimatedSprite.play("idle")

I tried this out and it worked but the problem was it only played the first frame of the idle animation

Hmm, does the animation not loop? Is that expected? Or rather, would it be fine if the "idle" animation looped?

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.