+2 votes

I want a dialogue box to pop up when I enter the specific area, and press the accept key (z in my case) but when I use my code, the dialogue doesn't work. The dialogue pops up when I make my code have it pop up when I just enter the area, but not with the if statement. What am I doing wrong?

   func _on_ComputerDetector_area_entered(area):
    if Input.get_action_strength("ui_accept"):
in Engine by (51 points)
edited by

Please use the Code-Sample formatting for your code (The { } above the text editor)
This makes your posts much more readable, and wont remove the underscores

2 Answers

–1 vote
Best answer

just executes the frame you really ENTER the area. It does not check if you are inside.
You can set a variable to true if you enter, and back to false when you exit. Then check this variable, because it can tell you if you are inside or not. (faster)

You can also use get_overlapping_areas() (or bodies) (slower)

by (1,528 points)
selected by
+1 vote

I think the code should be Input.is_action_pressed("ui_accept"), provided that the "z" key is bound to the "ui_accept" action, and that you account for when the player has entered the Area2D.

by (3,072 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.