How do I detect when the player has walked into a certain area?

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

For example in a 2D game if my character walks behind a tree, I want that tree to become translucent. Prior to Godot 3.0, I believe you could set a CollisionShape2D and then click the trigger option, to see if an object entered a certain area, I don’t know how to do this now.

:bust_in_silhouette: Reply From: oofman

Now you need to use Area2D and then inside CollisionShape2D nodes:

example project image showing Area2D nodes tree

After you do that you connect and use signals like area_entered or body_entered:

example project image showing signals and script window

:bust_in_silhouette: Reply From: dragon

I found out the answer is to attach an AreaDetector2D to the object you want to react to the trigger object which enters the trigger area. You then attach a CollisionShapePolygon2D or a CollisionShape2D to the AreaDetector2D, and then click on the Node tab for the AreaDetector2D, click on body_entered and then click on connect a popup dialog will appear and then click on the original object for example if you named that object a “wall”, then click connect. Godot will then create a listener function for you to write your code into for example you want to make the wall transparent or translucent or whatever you can do it here.

Basically it’s explained well in this link