This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

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 onDoorbodyentered 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.

in Engine by (23 points)

1 Answer

+1 vote

You're right. onbodyentered 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:
by (162 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.