0 votes

Greetings! Good to see you all, folks.

So, I'm still starting with Game Design in general, and I've chosen to learn Godot (I've been using it for ~2 months or so now, and I'm having a blast), but I've hit a brick wall:

I'm trying to show a label whenever my character enters an area2D that is part of a specific group (Let's call it "interactable").

So:

Image01

Here is Miller, chilling in front of this knife.

IF MILLER ENTERS THIS AREA2D (that makes part of the "Interactable" group, I'd like to make a label with an "!" appear (with .show()).

Nice, a Knife

I know I could use something like:

"func _on_KnifeInteract_body_entered(body):
  >  $Player.notification.show()"

Where notification is a label (or image) with the ! symbol.

But I'd end up replicating a lot of code (for every interactable object I would end up using this, and that's not cool!)

I'm wondering on how should I approach this.
Thanks in advance!

in Engine by (15 points)

1 Answer

+1 vote
Best answer

One alternative is to make these interactive objects Area2Ds (Their root is an Area2D and their script extends Area2D as well). Then put an Area2D on your character, and connect the area_entered signal for that character.

Then you may want to set up a special collision layer / mask for these to limit what triggers it.

When these interactive objects enter, the character code will just check which area has entered it, show his ! mark, and process how you wish from there. The interactive object should be the area that comes in, and its script will be accessible too.

There are many ways of mixing and matching these concepts, hard to say which best fits your project.

by (5,206 points)
selected by

I did exactly that a moment ago and it worked. Thanks!

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 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 webmaster@godotengine.org with your username.