Currently, I’m using Godot 4 for a little programming project of mine. In it, there’s going to be a little dialog feature where, if the player character overlaps with a defined Area2D node, and if the player presses a specific button, the dialog will trigger. I’ve been able to get the dialog to trigger on its own, but attempting to use Area2D and input detection is where it all goes wrong.
Keep in mind that, although I’ve had Godot for a while, now, I still am very new to the use of GDScript. Currently, the line of code I’m using draws no errors, but doesn’t trigger at all. Would there be a way I could actually make it trigger? Thanks!
This is what I have down:
You can find initial infos about input handling here in the docs: Using InputEvent — Godot Engine (stable) documentation in English
One thing that is not obvious from the documenation, is which kind of input events are received in the different input-functions. The following graphic helps with that:
As you can see, you listen to the _input_event
signal and that signal processes only MouseButton
, MouseMotion
, ScreenDrag
and ScreenTouch
input events.
You mention, that you wait until the “player presses a specific button”. I assume, that you mean, that the player “presses a specific button on the keyboard”. The best way to deal with that situation would be to not listen to the input_event
signal, but to override the _unhandled_key_input()
function instead.
If you mean to listen to joypad buttons, then you should override the _unhandled_input()
function instead of listening to the input_event
signal.
1 Like
Thanks! I’ll try seeing how it’ll help if and when I get the chance
I can not begin to explain how thankful I am for the help!! I’m gonna see if it still works when detecting stuff within the Area2D, next.
1 Like
Wait, super sorry if I’m taking up too much time. In case I’m not terribly missing something, would _unhandled_input() also cover CharacterBody2D interactions with Area2D nodes or will I have to enter some different things for that?
Physics interaction between nodes, that inherit fromCollisionObject2D
(like CharacterBody2D
or Area2D
) is handled by the physics implementation of the engine.
And that part has nothing to do with _unhandled_input()
.
_unhandled_input()
is only there to handle InputEvent
s.
Regarding physics interaction, you could for example head over to the documentation here: Using Area2D — Godot Engine (stable) documentation in English. Or alternatively try out the Getting-Started-Tutorial Your first 2D game “Dodge the Creeps”.
1 Like