How to make area2d work only on button click

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Newby
:warning: Old Version Published before Godot 3 was released.

I have a n area2d in front of my player as the attack box but the enemy’s area2d always detects it, how can i make it so that the enemy will only detect when the player attacks

:bust_in_silhouette: Reply From: Will Nations

You can make it so that the player node handling the input toggles the Area2D’s monitoring and monitorable properties to essentially blind it and make it invisible to other Area2D’s. In 2.1, I believe that would be with set_monitoring(bool) and set_monitorable(bool), but I’m not 100% sure. If nothing else, you can just do area2d_node.set("monitorable", false) to make it invisible.

:bust_in_silhouette: Reply From: eons

From the player side, do a player_attack_area.get_overlapping_areas() when the attack is active, that should give you the list of enemy areas in the attack zone.