Door not receiving input?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Andromachus

I’m currently having issues trying to implement a door open command. the idea is that when the player enters the door’s collision, it emits a signal that will then run an if statement to see if the player is pressing the open key. The code is shown below:

func _on_Door_body_entered(body):
	if Input.is_action_pressed("open"):

The issue is that it will allow the game to load the next scene, but only if the player is holding the open key prior to entering the door’s collision shape. I believe (i’m still new so please correct me) that the issue is that the _on_Door_body_entered signal is only being sent when the player first enters the collision shape, but not while the player is still colliding with it. Is there a way for me to have the door constantly emit a signal while the player is in its area, or should i find a different method for checking this? any help would be greatly appreciated.

:bust_in_silhouette: Reply From: Omar13

You’re right. on_body_entered is only called when the body enters the collider.
what you can do is

var is_inside := false

func on_body_entered(body):
    is_inside = true

func on_body_exited(body):
    is_inside = false

func unhandled_input(event: InputEvent) -> void:
     if Input.is_action_pressed("open"):
         if is_inside: