How do you connect an Area node to for NPC/Object Interaction?

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

Hi,

I have been working on this for a while now and I finally figured out how I can make a working dialogue box with branching properties (this is a .JSON file)

Now I want it to connect to the Main Scene of mine where a dummy character is standing still and has the Area node attached to him. I must add that it is the 3D world / scene. I know that the Area node is able to send a signal to the code where it can say if a Body has entered or left.

I want the code to do following:

  • Stop the movement of the character when interacting with the Dummy Character(No further inputs of the player with the WASD Keys which can change the position of the character) this will be the case until every piece of dialogue has been read or skipped. Releasing the input block and continue the normal WASD movement.

  • Input of the player is going to be “Enter” to continue the dialogue

I myself do have some code (shown below) but you can also advice me to use a whole different set of lines of code.


extends Area

const PLAYERNAME = “Mairobi”

export(String) var DialogueName = “”
export(String) var DialogueText = “”

func _ready():
connect(“body_entered”, self, “_on_body_enter”)
connect(“body_exited”, self, “on_body_exit”)

func _process(delta):
if Input.is_action_just_pressed(“ui_accept”):
var bodies = get_overlapping_bodies()
for body in bodies:
if (body.get_name() == PLAYERNAME):
print(body.get_name() + “interacts with” + get_name())
var textbox = get_node(“Area/Panel”)
textbox.setDialog(DialogueName, DialogueText)
textbox.transitionInOut(true)

func _on_body_enter(body):
print(body.get_name() + “entered the area”)

func _on_body_exit(body):
print(body.get_name() + “exited the area”)
if(body.get_name() == PLAYERNAME):
var textbox = get_node(“…/Textbox”)
textbox.transitionInOut(false)


I am not sure if I need to make more nodes or I need to have another piece of code made.

Thanks for reading
KindoSaur Productions

:bust_in_silhouette: Reply From: null_digital

You could use finite state machines here. When player begins conversation with NPC, leave “walking” state an enter “dialogue” state. When reading player’s input, in addition to checking action pressed, check state. If input is “WASD” AND state is “walking”, move.