The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

Hello this code executes an animation when it is detected that the player has touched a floor

if get_slide_count() != 0:
        var body = get_slide_collision(get_slide_count()-1)
        if body.normal == Vector2(0,-1) and body.collider.is_in_group("puas"):

The problem is that since the player is constantly touching the floor, the animation runs many times.
How would I make him

in Engine by (90 points)

2 Answers

0 votes

Change the last 2 lines to:

if body.normal == Vector2(0,-1) and body.collider.is_in_group("puas") and get_node("../Puas/anim".is_playing():

The extra is_playing() check will make it so that the animationplayer will only restart if it is not currently playing.

Hope this helps

by (399 points)
edited by

PS: I fixed the formatting in the answer. For the record, you need to separate the code sample from the rest of the text with one blank line above and below, and indent all lines with 4 spaces. (Other intendation should add 4 spaces on top of that, for every indentation level.)

Oh thanks for the heads up, I'm pretty new on these forums so that is good to know!

Also note that your answer is fixing a non-existent problem: "If the animation was already playing, it will keep playing." (Source)

0 votes

If you want the animation to only play once, use a boolean:

var triggered = false

# ...

if not triggered:
    triggered = true
by (10,634 points)
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.