how to code stand in front of door to open

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

so i’m working on a platformer and i want to implement doors that you can hide in to avoid enemies. i would be able to do it myself but i want it so that the character has to be standing in from of the door when they press the input button, then it’ll only work. the problem is, i haven’t the foggiest clue how to code this

i’m relatively new to coding and everything and still haven’t had the time to get around to reading the godot engine documentation in full so that might be part of the reason i don’t know how to code this particular part of my project.

anyway, here’s the code i have going on right now, that does not work.

extends Area2D

func _ready():

func _on_dooor_area_entered(area):
	if Input.is_action_just_pressed("enter"):
:bust_in_silhouette: Reply From: Lopy

Instead of using the entered and exited signal, you can check using the get_overlapping_bodies() and get_overlapping_areas() functions.

Give your doors and your player Areas, and inside the player’s _input() check the player’s Area for any nearby door with get_overlapping_areas(). That way, you not only know that the action is possible, but can work back the door to use (using get_node() on the overlapping Area).

While this is a nice solution, how will it affect performance?

Ertain | 2021-01-03 01:38