Play It Backwards
Part of the Game Feel section of Coddy's Godot journey. Lesson 23 of 23.
The door has one animation, "open". The panel slides up and the light turns from coral to mint. Closing is the same motion in reverse, so you do not need a second animation.
$AnimationPlayer.play_backwards("open")play_backwards plays an animation from its last key to its first. The panel slides back down and the light turns coral again.
Playing "open" forward would not close the door. It would start again from the first key, closed, and slide open.
Challenge
EasyE opens the door. Make E close it when it is open. In the if is_open: branch, play "open" backwards.
Try it yourself
extends Node2D
var is_open = false
func _process(delta):
if Input.is_action_just_pressed("action"):
if is_open:
pass
else:
$AnimationPlayer.play("open")
is_open = not is_open
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Game Feel
Practice on your own: Godot playground