Door animation code will not work properly.

Godot Version

4.3

Question

My code is not working. I am attempting to create a door and have done the animation already, however the code won’t work:

Area.gd

extends Area2D

var can_open_door = false
var door_opened = false

connect area signal

func _on_body_entered(body):
if body == $Player:
can_open_door = true

connect area signal

func _on_body_exited(body):
if body == $Player:
can_open_door = false

func _input(event):
if event is InputEventKey:
if event.scancode == KEY_E and can_open_door:
if door_opened:
close_door(q)
else:
open_door(e)

        # Toggle door_open bool
         door_opened = !door_opened

Have you set the animation mode to “discrete” in the animation editor?

Also, where is the code that should trigger the animation?

Are you sure $Player is really your player instance and the if statement works?

Also… Is this just the missing indentation? How does the if else block really looks like in your code?

if event is InputEventKey:
if event.scancode == KEY_E and can_open_door:
if door_opened:
    close_door(q)
else:
    open_door(e)