Could anyone help me with scene detection?

Godot Version

Question

Could anyone help me program this please? Basically, if the collation or area is touching “hero” then it will make a signal. Just hero I want it to be. I remember doing this and it was every scene it touched and not just hero.

Ehm… lets try this…

Create a script

extends Area2D

signal hero_detected
signal hero_exited

func _ready():
    # Connect the built-in area detection signals
    area_entered.connect(_on_area_entered)
    area_exited.connect(_on_area_exited)
    body_entered.connect(_on_body_entered)
    body_exited.connect(_on_body_exited)

# Check for Area2D collisions
func _on_area_entered(area: Area2D):
    if area.name == "hero":
        hero_detected.emit()

func _on_area_exited(area: Area2D):
    if area.name == "hero":
        hero_exited.emit()

# Check for physics body collisions
func _on_body_entered(body: Node2D):
    if body.name == "hero":
        hero_detected.emit()

func _on_body_exited(body: Node2D):
    if body.name == "hero":
        hero_exited.emit()

Then

Create an Area2D node in your scene and attach the script to your Area2D node. After that add a CollisionShape2D as a child of the Area2D
(set up the collision shape thingy) and Connect the signals in the editor to handle the hero detection

func _on_hero_detected():
    print("Hero entered the area!")

func _on_hero_exited():
    print("Hero left the area!")

Hopefully gets this you in the right direction :wink:

thx for your help!