0 votes

I am implementing ladders in my 2D platformer.

The user presses up or down when the Player node intersects a Ladder node to enter a climb state. This also snaps the Player to the Ladder and disables gravity. If the user releases the up or down button, the Player stays put on the Ladder.

When in the climb state, I only want to play my climb animation when the user is holding up or down. If they release the button, I want the animation to freeze.

How can I achieve this in Godot 3.0?

I am controlling my animations with an AnimationPlayer.

in Engine by (1,570 points)

1 Answer

+1 vote
Best answer

You might want to create a state machine for you character and show animatiions based on the character's state, but the most direct way is just:

if Input.isactionpressed("nameofaction"):
$AnimationPlayer.play("name of animation")

and:

if Input.is_action_just_released("name_of_action"):
     $AnimationPlayer.stop(false)

The false parameter tells the AnimationPlayer not to reset the animation.

by (530 points)
selected by

Thanks for the answer! I do use a state machine. I will take your suggestion and whenever my Player is in the climb state, I will check whether input is pressed or not. Depending on the input, I will play or pause the animation.

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.