+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"):
        $Speech.show()
asked Jun 25 in Engine by CatRass (45 points)
edited Jun 25 by CatRass

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
[...]_on_area_entered(area):

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)

answered Jun 25 by whiteshampoo (987 points)
selected Jun 25 by CatRass
+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.

answered Jun 25 by Ertain (1,389 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 How to use this Q&A? before posting your first questions.