How to Open ad close door in 2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By szccornish

when i open the door is working. but i cant close it anymore.

extends Area2D

var bodyNearDoor = false

onready var animationDoor = $AnimationDoor

func _process(delta):
if Input.is_action_just_pressed("Interact"):
	if bodyNearDoor == true :"Door_Open")
	if"Door_Open") == true :  <---- This doesnt work

func _on_Door_body_entered(body):
if == "Player":
	bodyNearDoor = true

func _on_Door_body_exited(body):
if == "Player":
	bodyNearDoor = false
:bust_in_silhouette: Reply From: LoneDespair

If you’re using an AnimatedSprite2D, otherwise pls let us know

if animationDoor.animation == "Door_Open":"Door_Close")

no i use sprite and animationplayer

szccornish | 2021-02-24 11:06

if animationDoor.assigned_animation == "Door_Open""Door_Close")

LoneDespair | 2021-02-24 11:15

:bust_in_silhouette: Reply From: whiteshampoo

(i guess animationDoor is an AnimationPlayer)

You need to save the “state” of the door.
You also might to check if the other animation is still playing.


var is_open : bool = false

func _process(_delta : float) -> void:
    if Input.is_action_just_pressed("Interact"):
        if bodyNearDoor and not animationDoor.is_playing():
            if not is_open:
                is_open = true
                is_open = false



:bust_in_silhouette: Reply From: Inces

The part that you indicated as not working is using wrong built-in function.
It should be :
if == true and animationdoor.current-animation == “Door Open”