0 votes
extends RayCast

func _ready():
    set_process(true)

var doorOpen = false

func _process(delta):
    if is_colliding():
        var obj = get_collider()
        var objname = obj.get_name()

        if objname == "button01" && doorOpen == false && Input.is_action_just_pressed("use"):
            var door = get_node("/root/test/door01")
            var dooranim = door.get_node("AnimationPlayer")
            dooranim.play("open")
            doorOpen = true

        if objname == "button01" && doorOpen == true && Input.is_action_just_pressed("use"):
            var door = get_node("/root/test/door01")
            var dooranim = door.get_node("AnimationPlayer")
            dooranim.play("close")
            doorOpen = false

I don't know what I'm doing wrong. The door should play the "open" animation when "doorOpen" is false, but it keeps playing the "close" animation.

in Engine by (15 points)

1 Answer

0 votes
Best answer

Notice how you have two conditional statements executing one after the other? This is happening because you have two "if" statements that are sequential. Your code checks to see if a button is pressed and then plays the open animation. But then it moves on to play the other animation as well. Turn the second "if" statement into an "elif" statement.

by (1,875 points)
selected by
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.