@onready var player = get_node(“res://Scenes/Player.tscn”)
Door.
@onready var animation = $AnimatedSprite2D @onready var collision = $CollisionShape2D
var is_open = false
func _on_interact_collision_area_entered(area):
player = area.get_parent()
if player is Player and is_open == false:
collision.set_deferred(“disabled”, true)
animation.play(“Open”)
is_open = true
if player is Player and is_open == true:
collision.set_deferred("disabled", false)
animation.play("Close")
is_open = false
Player:
Object interaction.
if Input.is_action_just_pressed("Interact"):
interact_collison.set_deferred("disabled", false)
animation.play("Interact")
else:
interact_collison.set_deferred("disabled", true)
Question
I’m trying to make a door so that it changes it’s sprite to the open or close animation as well as the collision disabling or enabling when the interaction hitbox of the player touches the door interact hitbox.
The player interaction does work, but when I use it on the door nothing happens. Though I did try this.
if player is Player:
collision.set_deferred("disabled", true)
animation.play("Open")
is_open = true
And got rid of the close if statement, and it worked so it seems the is_open doesn’t work with it but i’m not sure what to do to check if it is open or not.
Aha you should be using a elif statement here, the two if statements happen in order, so is_open is set to true, then it checks if is_open is true and sets it back to false. elif means only one of the statements will run, not both.
if player is Player and is_open == false:
collision.set_deferred("disabled", true)
animation.play("Open")
is_open = true
elif player is Player and is_open == true:
collision.set_deferred("disabled", false)
animation.play("Close")
is_open = false