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 :
        animationDoor.play("Door_Open")

    if animationDoor.play("Door_Open") == true :  <---- This doesnt work
        animationDoor.Play("Door_Close")

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


func _on_Door_body_exited(body):
if body.name == "Player":
    bodyNearDoor = false
Godot version 3.2.1
in Engine by (68 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 animationdoor.is-playing() == true and animationdoor.current-animation == "Door Open"

by (7,305 points)
selected by
+1 vote

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

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

no i use sprite and animationplayer

if animationDoor.assigned_animation == "Door_Open"
    animationDoor.play("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:
                animationDoor.play("Door_Open")
                is_open = true
            else:
                animationDoor.Play("Door_Close")
                is_open = false

#[...]

(untested)

by (1,520 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.