Can you make a player detector (Area2D) script that when you press a key (E), it makes an action?

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

I found this script a bit messy and uncluttered, can you make this shorter (without using street_sign_player_inside and placing the input function inside the signal), thanks.

Script:

extends Node2D
onready var player = $YSort/Characters/Player #Directory to player

func _input(event):
if event.is_action_pressed(“ui_interact”) && street_sign_player_inside:
player.talk(#Some variables)

func _on_StreetSign_body_entered(body):
if !body.is_in_group(“Player”):
return
street_sign_player_inside = true

func _on_StreetSign_body_exited(body):
if !body.is_in_group(“Player”):
return
street_sign_player_inside = false

:bust_in_silhouette: Reply From: Inces

You don’t need signals here.

On input(event):
       if Input is interact :
             if player.overlaps_area(sign) :
                    player.talk

This is semi-pseudocode. Alternatively You can use for body in get_overlapping_bodies(or areas, depending ony our classes )()
.

Thanks, it worked!

Ultra8Gaming | 2021-03-31 01:07