The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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
Godot version 3.2.1
in Engine by (69 points)

3 Answers

+1 vote
Best answer

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"

by (8,188 points)
selected by
+1 vote

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

if animationDoor.animation == "Door_Open":"Door_Close")
by (410 points)

no i use sprite and animationplayer

if animationDoor.assigned_animation == "Door_Open""Door_Close")
+1 vote

(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



by (1,536 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 Frequently asked questions and 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 [email protected] with your username.