Super basic NPC dialogue?

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

Sorry for the noob-ness, but I’m looking to create a very basic interaction between the player and an NPC in my 2D RPG, where the player approaches the NPC and interacts with them and a dialogue box pops up with a simple message. I’ve created the player and the NPC, but haven’t been able to make anything happen.

I don’t even have any sample code to share because I’ve tried following several tutorials but not gotten anywhere, and I think I need to take a step back and get a fresh perspective.

So any guidance on the most basic way to cause a player action to trigger an NPC response would be hugely appreciated!

:bust_in_silhouette: Reply From: exuin

I’ll give you one way to do this:

Have an Area2D on the player character and another one on the NPC. On the player, check for input and if the input is the correct input for interaction, check if the player is in the NPC’s area. If it is, then pop up the dialogue box.

This sounds good - what kind of code would be needed to make the dialogue box pop up?


samjmiller | 2021-03-06 18:27

Simply showing and hiding the dialogue box would be enough.

exuin | 2021-03-06 18:50