Animation plays when it's not supposed to play.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ItsAnysek
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.

:bust_in_silhouette: Reply From: johnygames

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.