How to have something popup w/ interaction

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

How am I able to have my purple character interact with my blue character so a dialogue box will popup?

Example image of what I’m trying to do

If you’re able to help, thanks so much!!

So your issue is that you have created a pop-up menu, but you need to make it appear when the purple character “walks into” the blue one?

If that’s the case, you should use an area2D node with a collision shape around the blue player. The Area2D node should have a signal associated with it that will be called when a purple player enters into it (assuming the purple player either is a rigid or kinematic body, or also has an area2d node as well)

RedBlueCarrots | 2020-05-11 12:02

What if I were to use Input.is-action-just-pressed()?
How would I do it then?

Yumii_ | 2020-05-11 12:18

There are a few ways to do it, however in order to have the code be more flexible i would recommend:

If Input.is_action_just_pressed() and $Area2D.get_overlapping_areas.size() > 0:

$Area2D refers to the area node which is a child of your player node, and it needs to collide with an area2d node which is a child of the other character node.

Then under the if statement write:

If $Area2D.get_overlapping_areas()[0].has_method("open_popup"):
    $Area2D.get_overlapping_areas()[0].open_popup()

This will run the “open_popup” (feel free to rename) function in the scrip attached to the area node under the other character. If you want to access the script attached to the character node instead of their area node:

If $Area2D.get_overlapping_areas()[0].get_parent().has_method("open_popup"):
    $Area2D.get_overlapping_areas()[0].get_parent().open_popup()

I hope that wasn’t too confusing of an explanation

RedBlueCarrots | 2020-05-11 13:11

Would it look something like this?
Would I have to change anything or is it fine?

(Kai is the blue character)

Yumii_ | 2020-05-11 20:55