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

asked May 10 in Projects by Yamz (73 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

answered May 11 by RedBlueCarrots (211 points)
edited May 11 by Calinou

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
answered May 11 by njamster (8,986 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 How to use this Q&A? before posting your first questions.