0 votes

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


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

func input(event):
if event.is
actionpressed("uiinteract") && streetsignplayer_inside:
player.talk(#Some variables)

func onStreetSignbodyentered(body):
if !body.isingroup("Player"):
streetsignplayer_inside = true

func onStreetSignbodyexited(body):
if !body.isingroup("Player"):
streetsignplayer_inside = false

Godot version 3.2.3
in Engine by (25 points)
edited by

1 Answer

+1 vote
Best answer

You don't need signals here.

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

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

by (1,110 points)
selected by

Thanks, it worked!

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.