0 votes

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!!

in Engine by (12 points)

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)

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

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

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

(Kai is the blue character)

Please log in or register to answer this question.

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.